mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix: resource advanced view filter.
This commit is contained in:
@@ -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',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user