mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
87
packages/server/src/modules/Import/models/Import.ts
Normal file
87
packages/server/src/modules/Import/models/Import.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { Model, ModelObject } from 'objection';
|
||||
// import SystemModel from './SystemModel';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
|
||||
export class Import extends BaseModel {
|
||||
resource: string;
|
||||
tenantId: number;
|
||||
mapping!: string;
|
||||
columns!: string;
|
||||
params!: string;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'imports';
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['mappingParsed'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the import is mapped.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public get isMapped() {
|
||||
return Boolean(this.mapping);
|
||||
}
|
||||
|
||||
public get columnsParsed() {
|
||||
try {
|
||||
return JSON.parse(this.columns);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public get paramsParsed() {
|
||||
try {
|
||||
return JSON.parse(this.params);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public get mappingParsed() {
|
||||
try {
|
||||
return JSON.parse(this.mapping);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Tenant = require('system/models/Tenant');
|
||||
|
||||
return {
|
||||
/**
|
||||
* System user may belongs to tenant model.
|
||||
*/
|
||||
tenant: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Tenant.default,
|
||||
join: {
|
||||
from: 'imports.tenantId',
|
||||
to: 'tenants.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type ImportShape = ModelObject<Import>;
|
||||
Reference in New Issue
Block a user