fix: add count property to item categories list response.

This commit is contained in:
Ahmed Bouhuolia
2020-11-29 17:59:52 +02:00
parent a4195069c7
commit 62bfc1fc5c

View File

@@ -269,6 +269,9 @@ export default class ItemCategoriesService implements IItemCategoriesService {
const dynamicList = await this.dynamicListService.dynamicList(tenantId, ItemCategory, filter);
const itemCategories = await ItemCategory.query().onBuild((query) => {
// Subquery to calculate sumation of assocaited items to the item category.
query.select('*', ItemCategory.relatedQuery('items').count().as('count'));
dynamicList.buildQuery()(query);
});
return { itemCategories, filterMeta: dynamicList.getResponseMeta() };