mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
add server to monorepo.
This commit is contained in:
62
packages/server/src/models/ItemCategory.ts
Normal file
62
packages/server/src/models/ItemCategory.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Model, mixin } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import ModelSetting from './ModelSetting';
|
||||
import ItemCategorySettings from './ItemCategory.Settings';
|
||||
|
||||
export default class ItemCategory extends mixin(TenantModel, [ModelSetting]) {
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'items_categories';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Item = require('models/Item');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Item category may has many items.
|
||||
*/
|
||||
items: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: Item.default,
|
||||
join: {
|
||||
from: 'items_categories.id',
|
||||
to: 'items.categoryId',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Model modifiers.
|
||||
*/
|
||||
static get modifiers() {
|
||||
return {
|
||||
/**
|
||||
* Inactive/Active mode.
|
||||
*/
|
||||
sortByCount(query, order = 'asc') {
|
||||
query.orderBy('count', order);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Model meta.
|
||||
*/
|
||||
static get meta() {
|
||||
return ItemCategorySettings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user