fix: resource advanced view filter.

This commit is contained in:
Ahmed Bouhuolia
2020-09-16 21:41:09 +02:00
parent a22c8395f3
commit ca92c925a9
72 changed files with 997 additions and 2324 deletions

View File

@@ -1,52 +0,0 @@
import { Model } from 'objection';
import TenantModel from 'models/TenantModel';
export default class Resource extends TenantModel {
/**
* Table name.
*/
static get tableName() {
return 'resources';
}
/**
* Timestamp columns.
*/
static get hasTimestamps() {
return false;
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const View = require('models/View');
const ResourceField = require('models/ResourceField');
return {
/**
* Resource model may has many views.
*/
views: {
relation: Model.HasManyRelation,
modelClass: this.relationBindKnex(View.default),
join: {
from: 'resources.id',
to: 'views.resourceId',
},
},
/**
* Resource model may has many fields.
*/
fields: {
relation: Model.HasManyRelation,
modelClass: this.relationBindKnex(ResourceField.default),
join: {
from: 'resources.id',
to: 'resource_fields.resourceId',
},
},
};
}
}

View File

@@ -1,70 +0,0 @@
import { snakeCase } from 'lodash';
import { Model } from 'objection';
import path from 'path';
import TenantModel from 'models/TenantModel';
export default class ResourceField extends TenantModel {
/**
* Table name.
*/
static get tableName() {
return 'resource_fields';
}
static get jsonAttributes() {
return ['options'];
}
/**
* Model modifiers.
*/
static get modifiers() {
return {
whereNotPredefined(query) {
query.whereNot('predefined', true);
},
};
}
/**
* Timestamp columns.
*/
static get hasTimestamps() {
return false;
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return ['key'];
}
/**
* Resource field key.
*/
key() {
return snakeCase(this.labelName);
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Resource = require('models/Resource');
return {
/**
* Resource field may belongs to resource model.
*/
resource: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Resource.default),
join: {
from: 'resource_fields.resourceId',
to: 'resources.id',
},
},
};
}
}

View File

@@ -1,10 +0,0 @@
import TenantModel from 'models/TenantModel';
export default class ResourceFieldMetadata extends TenantModel {
/**
* Table name.
*/
static get tableName() {
return 'resource_custom_fields_metadata';
}
}

View File

@@ -12,7 +12,7 @@ export default class View extends TenantModel {
/**
* Model timestamps.
*/
static get timestamps() {
get timestamps() {
return ['createdAt', 'updatedAt'];
}
@@ -40,23 +40,10 @@ export default class View extends TenantModel {
* Relationship mapping.
*/
static get relationMappings() {
const Resource = require('models/Resource');
const ViewColumn = require('models/ViewColumn');
const ViewRole = require('models/ViewRole');
return {
/**
* View model belongs to resource model.
*/
resource: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Resource.default),
join: {
from: 'views.resourceId',
to: 'resources.id',
},
},
/**
* View model may has many columns.
*/

View File

@@ -13,20 +13,9 @@ export default class ViewColumn extends TenantModel {
* Relationship mapping.
*/
static get relationMappings() {
const ResourceField = require('models/ResourceField');
return {
/**
* View role model may belongs to resource field model.
*/
field: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(ResourceField.default),
join: {
from: 'view_has_columns.fieldId',
to: 'resource_fields.id',
},
},
};
}
}

View File

@@ -27,7 +27,6 @@ export default class ViewRole extends TenantModel {
* Relationship mapping.
*/
static get relationMappings() {
const ResourceField = require('models/ResourceField');
const View = require('models/View');
return {
@@ -42,18 +41,6 @@ export default class ViewRole extends TenantModel {
to: 'views.id',
},
},
/**
* View role model may belongs to resource field model.
*/
field: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(ResourceField.default),
join: {
from: 'view_roles.fieldId',
to: 'resource_fields.id',
},
},
};
}
}

View File

@@ -15,7 +15,6 @@ import PaymentReceiveEntry from './PaymentReceiveEntry';
import Bill from './Bill';
import BillPayment from './BillPayment';
import BillPaymentEntry from './BillPaymentEntry';
import Resource from './Resource';
import View from './View';
import ItemEntry from './ItemEntry';
import InventoryTransaction from './InventoryTransaction';
@@ -39,7 +38,6 @@ export {
Bill,
BillPayment,
BillPaymentEntry,
Resource,
View,
ItemEntry,
InventoryTransaction,