feat: clean up the imported temp files

This commit is contained in:
Ahmed Bouhuolia
2024-04-09 00:09:32 +02:00
parent aaa8f39e50
commit 0684e50ebd
22 changed files with 239 additions and 88 deletions

View File

@@ -0,0 +1,86 @@
import { Model, ModelObject } from 'objection';
import SystemModel from './SystemModel';
export class Import extends SystemModel {
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>;

View File

@@ -5,6 +5,11 @@ import BaseModel from 'models/Model';
import TenantMetadata from './TenantMetadata';
export default class Tenant extends BaseModel {
upgradeJobId: string;
buildJobId: string;
initializedAt!: Date | null;
seededAt!: Date | null;
/**
* Table name.
*/
@@ -14,6 +19,7 @@ export default class Tenant extends BaseModel {
/**
* Timestamps columns.
* @returns {string[]}
*/
get timestamps() {
return ['createdAt', 'updatedAt'];
@@ -21,6 +27,7 @@ export default class Tenant extends BaseModel {
/**
* Virtual attributes.
* @returns {string[]}
*/
static get virtualAttributes() {
return ['isReady', 'isBuildRunning', 'isUpgradeRunning'];
@@ -28,6 +35,7 @@ export default class Tenant extends BaseModel {
/**
* Tenant is ready.
* @returns {boolean}
*/
get isReady() {
return !!(this.initializedAt && this.seededAt);
@@ -35,6 +43,7 @@ export default class Tenant extends BaseModel {
/**
* Detarimes the tenant whether is build currently running.
* @returns {boolean}
*/
get isBuildRunning() {
return !!this.buildJobId;
@@ -42,6 +51,7 @@ export default class Tenant extends BaseModel {
/**
* Detarmines the tenant whether is upgrade currently running.
* @returns {boolean}
*/
get isUpgradeRunning() {
return !!this.upgradeJobId;
@@ -64,6 +74,7 @@ export default class Tenant extends BaseModel {
},
};
}
/**
* Creates a new tenant with random organization id.
*/

View File

@@ -4,6 +4,7 @@ import SystemUser from './SystemUser';
import PasswordReset from './PasswordReset';
import Invite from './Invite';
import SystemPlaidItem from './SystemPlaidItem';
import { Import } from './Import';
export {
Tenant,
@@ -12,4 +13,5 @@ export {
PasswordReset,
Invite,
SystemPlaidItem,
Import,
};