diff --git a/services/loopback/common/methods/item/getSummary.js b/services/loopback/common/methods/item/getSummary.js index a08e02a72..0ed76e134 100644 --- a/services/loopback/common/methods/item/getSummary.js +++ b/services/loopback/common/methods/item/getSummary.js @@ -20,6 +20,7 @@ module.exports = Self => { }); Self.getSummary = async id => { + let promises = []; let summary = {}; // Item basic data and taxes @@ -59,7 +60,7 @@ module.exports = Self => { } ] }; - [summary.item] = await Self.app.models.Item.find(filter); + promises.push(Self.app.models.Item.find(filter)); // Tags filter = { @@ -70,28 +71,35 @@ module.exports = Self => { relation: 'tag' } }; - summary.tags = await Self.app.models.ItemTag.find(filter); + promises.push(Self.app.models.ItemTag.find(filter)); // Botanical filter = { where: {itemFk: id}, include: [{relation: 'genus'}, {relation: 'specie'}] }; - [summary.botanical] = await Self.app.models.ItemBotanical.find(filter); + promises.push(Self.app.models.ItemBotanical.find(filter)); // Niches filter = { where: {itemFk: id}, include: {relation: 'warehouse'} }; - summary.niches = await Self.app.models.ItemNiche.find(filter); + promises.push(Self.app.models.ItemNiche.find(filter)); + + let res = await Promise.all(promises); + + [summary.item] = res[0]; + summary.tags = res[1]; + [summary.botanical] = res[2]; + summary.niches = res[3]; // Visible Avaible let query = ` CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; let options = [summary.item.id, summary.item.itemType().warehouseFk, false]; - let [res] = await Self.rawSql(query, options); + [res] = await Self.rawSql(query, options); summary.available = res[0].available ? res[0].available : '-'; summary.visible = res[0].visible ? res[0].visible : '-';