feat: optimize dynamic list service.

feat: inactive mode for accounts, items, customers and vendors services.
This commit is contained in:
a.bouhuolia
2021-07-29 08:46:41 +02:00
parent 720dc5b7d7
commit 9186076676
80 changed files with 2748 additions and 1806 deletions

View File

@@ -1,20 +1,22 @@
import { Model } from "objection";
import TenantModel from "models/TenantModel";
import { buildFilterQuery } from "lib/ViewRolesBuilder";
import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
import { buildFilterQuery } from 'lib/ViewRolesBuilder';
import ItemSettings from './Item.Settings';
import ModelSetting from './ModelSetting';
export default class Item extends TenantModel {
export default class Item extends mixin(TenantModel, [ModelSetting]) {
/**
* Table name
*/
static get tableName() {
return "items";
return 'items';
}
/**
* Model timestamps.
*/
get timestamps() {
return ["createdAt", "updatedAt"];
return ['createdAt', 'updatedAt'];
}
/**
@@ -35,6 +37,13 @@ export default class Item extends TenantModel {
viewRolesBuilder(query, conditions, logicExpression) {
buildFilterQuery(Item.tableName, conditions, logicExpression)(query);
},
/**
* Inactive/Active mode.
*/
inactiveMode(query, active = false) {
query.where('active', !active);
},
};
}
@@ -42,9 +51,9 @@ export default class Item extends TenantModel {
* Relationship mapping.
*/
static get relationMappings() {
const Media = require("models/Media");
const Account = require("models/Account");
const ItemCategory = require("models/ItemCategory");
const Media = require('models/Media');
const Account = require('models/Account');
const ItemCategory = require('models/ItemCategory');
return {
/**
@@ -54,8 +63,8 @@ export default class Item extends TenantModel {
relation: Model.BelongsToOneRelation,
modelClass: ItemCategory.default,
join: {
from: "items.categoryId",
to: "items_categories.id",
from: 'items.categoryId',
to: 'items_categories.id',
},
},
@@ -63,8 +72,8 @@ export default class Item extends TenantModel {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
join: {
from: "items.costAccountId",
to: "accounts.id",
from: 'items.costAccountId',
to: 'accounts.id',
},
},
@@ -72,8 +81,8 @@ export default class Item extends TenantModel {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
join: {
from: "items.sellAccountId",
to: "accounts.id",
from: 'items.sellAccountId',
to: 'accounts.id',
},
},
@@ -81,8 +90,8 @@ export default class Item extends TenantModel {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
join: {
from: "items.inventoryAccountId",
to: "accounts.id",
from: 'items.inventoryAccountId',
to: 'accounts.id',
},
},
@@ -90,110 +99,21 @@ export default class Item extends TenantModel {
relation: Model.ManyToManyRelation,
modelClass: Media.default,
join: {
from: "items.id",
from: 'items.id',
through: {
from: "media_links.model_id",
to: "media_links.media_id",
from: 'media_links.model_id',
to: 'media_links.media_id',
},
to: "media.id",
to: 'media.id',
},
},
};
}
/**
* Item fields.
* Model settings.
*/
static get fields() {
return {
type: {
label: "Type",
column: "type",
},
name: {
label: "Name",
column: "name",
},
code: {
label: "Code",
column: "code",
},
sellable: {
label: "Sellable",
column: "sellable",
},
purchasable: {
label: "Purchasable",
column: "purchasable",
},
sell_price: {
label: "Sell price",
column: "sell_price",
},
cost_price: {
label: "Cost price",
column: "cost_price",
},
currency_code: {
label: "Currency",
column: "currency_code",
},
cost_account: {
label: "Cost account",
column: "cost_account_id",
relation: "accounts.id",
relationColumn: "accounts.name",
},
sell_account: {
label: "Sell account",
column: "sell_account_id",
relation: "accounts.id",
relationColumn: "accounts.name",
},
inventory_account: {
label: "Inventory account",
column: "inventory_account_id",
relation: "accounts.id",
relationColumn: "accounts.name",
},
sell_description: {
label: "Sell description",
column: "sell_description",
},
purchase_description: {
label: "Purchase description",
column: "purchase_description",
},
quantity_on_hand: {
label: "Quantity on hand",
column: "quantity_on_hand",
},
note: {
label: "Note",
column: "note",
},
category: {
label: "Category",
column: "category_id",
relation: "items_categories.id",
relationColumn: "items_categories.name",
},
active: {
label: "Active",
column: "active",
},
// user: {
// label: 'User',
// column: 'user_id',
// relation: 'users.id',
// relationColumn: 'users.',
// },
created_at: {
label: "Created at",
column: "created_at",
columnType: "date",
fieldType: "date",
},
};
static get meta() {
return ItemSettings;
}
}