mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: items list restful api.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { Model } from 'objection';
|
||||
import path from 'path';
|
||||
import BaseModel from '@/models/Model';
|
||||
import {
|
||||
buildFilterQuery,
|
||||
} from '@/lib/ViewRolesBuilder';
|
||||
|
||||
export default class Item extends BaseModel {
|
||||
/**
|
||||
@@ -10,10 +13,26 @@ export default class Item extends BaseModel {
|
||||
return 'items';
|
||||
}
|
||||
|
||||
static get modifiers() {
|
||||
const TABLE_NAME = Item.tableName;
|
||||
|
||||
return {
|
||||
sortBy(query, columnSort, sortDirection) {
|
||||
query.orderBy(columnSort, sortDirection);
|
||||
},
|
||||
viewRolesBuilder(query, conditions, logicExpression) {
|
||||
buildFilterQuery(Item.tableName, conditions, logicExpression)(query);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Account = require('@/models/Account');
|
||||
const ItemCategory = require('@/models/ItemCategory');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Item may has many meta data.
|
||||
@@ -32,12 +51,39 @@ export default class Item extends BaseModel {
|
||||
*/
|
||||
category: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelBase: path.join(__dirname, 'ItemCategory'),
|
||||
modelClass: ItemCategory.default,
|
||||
join: {
|
||||
from: 'items.categoryId',
|
||||
to: 'items_categories.id',
|
||||
},
|
||||
},
|
||||
|
||||
costAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'items.costAccountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
|
||||
sellAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'items.sellAccountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
|
||||
inventoryAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'items.inventoryAccountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user