fix: resource advanced view filter.

This commit is contained in:
Ahmed Bouhuolia
2020-09-16 21:41:09 +02:00
parent a22c8395f3
commit ca92c925a9
72 changed files with 997 additions and 2324 deletions

View File

@@ -1,5 +1,7 @@
import { difference } from "lodash";
import { Service, Inject } from "typedi";
import { IItemsFilter } from 'interfaces';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import TenancyService from 'services/Tenancy/TenancyService';
@Service()
@@ -7,6 +9,9 @@ export default class ItemsService {
@Inject()
tenancy: TenancyService;
@Inject()
dynamicListService: DynamicListingService;
async newItem(tenantId: number, item: any) {
const { Item } = this.tenancy.models(tenantId);
const storedItem = await Item.query()
@@ -71,4 +76,24 @@ export default class ItemsService {
writeItemInventoryOpeningQuantity(tenantId: number, itemId: number, openingQuantity: number, averageCost: number) {
}
/**
* Retrieve items datatable list.
* @param {number} tenantId
* @param {IItemsFilter} itemsFilter
*/
async getItemsList(tenantId: number, itemsFilter: IItemsFilter) {
const { Item } = this.tenancy.models(tenantId);
const dynamicFilter = await this.dynamicListService.dynamicList(tenantId, Item, itemsFilter);
const items = await Item.query().onBuild((builder) => {
builder.withGraphFetched('inventoryAccount');
builder.withGraphFetched('sellAccount');
builder.withGraphFetched('costAccount');
builder.withGraphFetched('category');
dynamicFilter.buildQuery()(builder);
});
return items;
}
}