feat: added inventory policies & modified APIs

This commit is contained in:
Sathishkumar Krishnan
2022-01-07 07:44:53 +05:30
parent a22b2adc5c
commit 046435c304
3 changed files with 103 additions and 6 deletions

View File

@@ -163,14 +163,34 @@ const createSublevels = async (subLevels, level, parent = undefined, depth = 0)
return sub_levels_list;
};
const createInventory = async ({ name, type }) => {
const createInventory = async ({ name, type, policies }) => {
if (!(name && type)) {
return;
}
const preferredLocations = [];
if (policies.preferredLocations && Array.isArray(policies.preferredLocations)) {
for (const preferredLocation of policies.preferredLocations) {
preferredLocations.push({ id: preferredLocation.id, type: preferredLocation.type });
}
}
const verifiedPolicies = {
orderTracking: policies.orderTracking || {},
alerting: {
lowestStockLevel: policies.alerting && policies.alerting.lowestStockLevel ? policies.alerting.lowestStockLevel : false,
highestStockLevel: policies.alerting && policies.alerting.highestStockLevel ? policies.alerting.highestStockLevel : false,
alertStockLevel: policies.alerting && policies.alerting.alertStockLevel ? policies.alerting.alertStockLevel : false,
reOrderLevel: policies.alerting && policies.alerting.reOrderLevel ? policies.alerting.reOrderLevel : false,
},
replenishment: policies.replenishment || {},
preferredLocations: preferredLocations,
};
return await Inventory.create({
name,
type,
policies: verifiedPolicies,
});
};