mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-05-11 21:34:57 +00:00
Custom fields feature.
This commit is contained in:
@@ -21,6 +21,11 @@ const Account = bookshelf.Model.extend({
|
||||
balances() {
|
||||
return this.hasMany('AccountBalance', 'accounnt_id');
|
||||
},
|
||||
}, {
|
||||
/**
|
||||
* Cascade delete dependents.
|
||||
*/
|
||||
dependents: ['balances'],
|
||||
});
|
||||
|
||||
export default bookshelf.model('Account', Account);
|
||||
|
||||
@@ -11,10 +11,18 @@ const Resource = bookshelf.Model.extend({
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
permissions() {
|
||||
/**
|
||||
* Resource model may has many views.
|
||||
*/
|
||||
views() {
|
||||
return this.hasMany('View', 'resource_id');
|
||||
},
|
||||
|
||||
roles() {
|
||||
/**
|
||||
* Resource model may has many fields.
|
||||
*/
|
||||
fields() {
|
||||
return this.hasMany('ResourceField', 'resource_id');
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
37
server/src/models/ResourceField.js
Normal file
37
server/src/models/ResourceField.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { snakeCase } from 'lodash';
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const ResourceField = bookshelf.Model.extend({
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
tableName: 'resource_fields',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
virtuals: {
|
||||
/**
|
||||
* Resource field key.
|
||||
*/
|
||||
key() {
|
||||
return snakeCase(this.attributes.label_name);
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Resource field may belongs to resource model.
|
||||
*/
|
||||
resource() {
|
||||
return this.belongsTo('Resource', 'resource_id');
|
||||
},
|
||||
}, {
|
||||
/**
|
||||
* JSON Columns.
|
||||
*/
|
||||
jsonColumns: ['options'],
|
||||
});
|
||||
|
||||
export default bookshelf.model('ResourceField', ResourceField);
|
||||
38
server/src/models/View.js
Normal file
38
server/src/models/View.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const View = bookshelf.Model.extend({
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
tableName: 'views',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
/**
|
||||
* View model belongs to resource model.
|
||||
*/
|
||||
resource() {
|
||||
return this.belongsTo('Resource', 'resource_id');
|
||||
},
|
||||
|
||||
/**
|
||||
* View model may has many columns.
|
||||
*/
|
||||
columns() {
|
||||
return this.belongsToMany('ResourceField', 'view_has_columns', 'view_id', 'field_id');
|
||||
},
|
||||
|
||||
/**
|
||||
* View model may has many view roles.
|
||||
*/
|
||||
viewRoles() {
|
||||
return this.hasMany('ViewRole', 'view_id');
|
||||
},
|
||||
}, {
|
||||
dependents: ['columns', 'viewRoles'],
|
||||
});
|
||||
|
||||
export default bookshelf.model('View', View);
|
||||
19
server/src/models/ViewColumn.js
Normal file
19
server/src/models/ViewColumn.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const ViewColumn = bookshelf.Model.extend({
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
tableName: 'view_columns',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
view() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
export default bookshelf.model('ViewColumn', ViewColumn);
|
||||
22
server/src/models/ViewRole.js
Normal file
22
server/src/models/ViewRole.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const ViewRole = bookshelf.Model.extend({
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
tableName: 'view_roles',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
/**
|
||||
* View role model may belongs to view model.
|
||||
*/
|
||||
view() {
|
||||
return this.belongsTo('View', 'view_id');
|
||||
},
|
||||
});
|
||||
|
||||
export default bookshelf.model('ViewRole', ViewRole);
|
||||
@@ -2,6 +2,7 @@ import Bookshelf from 'bookshelf';
|
||||
import jsonColumns from 'bookshelf-json-columns';
|
||||
import bookshelfParanoia from 'bookshelf-paranoia';
|
||||
import bookshelfModelBase from 'bookshelf-modelbase';
|
||||
import cascadeDelete from 'bookshelf-cascade-delete';
|
||||
import knex from '../database/knex';
|
||||
|
||||
const bookshelf = Bookshelf(knex);
|
||||
@@ -13,5 +14,6 @@ bookshelf.plugin('virtuals');
|
||||
bookshelf.plugin(jsonColumns);
|
||||
bookshelf.plugin(bookshelfParanoia);
|
||||
bookshelf.plugin(bookshelfModelBase.pluggable);
|
||||
bookshelf.plugin(cascadeDelete);
|
||||
|
||||
export default bookshelf;
|
||||
|
||||
Reference in New Issue
Block a user