fix: fixed createInventorySchema API
This commit is contained in:
@@ -128,12 +128,7 @@ const createLevels = async (levels, bay) => {
|
|||||||
return levelsArr;
|
return levelsArr;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createSublevels = async (
|
const createSublevels = async (subLevels, level, parent = undefined, depth = 0) => {
|
||||||
subLevels,
|
|
||||||
level,
|
|
||||||
parent = undefined,
|
|
||||||
depth = 0
|
|
||||||
) => {
|
|
||||||
const subLevelsArr = [];
|
const subLevelsArr = [];
|
||||||
for (const subLevel of subLevels) {
|
for (const subLevel of subLevels) {
|
||||||
const subLevelObj = await Sublevel.create({
|
const subLevelObj = await Sublevel.create({
|
||||||
@@ -148,12 +143,7 @@ const createSublevels = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (subLevel.sub_levels) {
|
if (subLevel.sub_levels) {
|
||||||
const subSubLevels = await createSublevels(
|
const subSubLevels = await createSublevels(subLevel.sub_levels, level, subLevelObj, depth + 1);
|
||||||
subLevel.sub_levels,
|
|
||||||
level,
|
|
||||||
subLevelObj,
|
|
||||||
depth + 1
|
|
||||||
);
|
|
||||||
|
|
||||||
subLevelObj.sub_levels = subSubLevels.map((_) => {
|
subLevelObj.sub_levels = subSubLevels.map((_) => {
|
||||||
return {
|
return {
|
||||||
@@ -212,7 +202,7 @@ const createItems = async (items, material) => {
|
|||||||
|
|
||||||
const createMaterials = async (materials, inventory, parent = undefined) => {
|
const createMaterials = async (materials, inventory, parent = undefined) => {
|
||||||
const materialsData = [];
|
const materialsData = [];
|
||||||
for (const materialData of materials) {
|
for (const { name, family, items } of materials) {
|
||||||
const material = await Material.create({
|
const material = await Material.create({
|
||||||
name,
|
name,
|
||||||
parent,
|
parent,
|
||||||
@@ -220,23 +210,19 @@ const createMaterials = async (materials, inventory, parent = undefined) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let materialFamily;
|
let materialFamily;
|
||||||
if (materialData.family) {
|
if (family) {
|
||||||
materialFamily = await createMaterials(
|
materialFamily = await createMaterials(family, inventory, material);
|
||||||
materialData.family,
|
|
||||||
inventory,
|
|
||||||
material
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let items;
|
let itemsList;
|
||||||
if (materialData.items) {
|
if (items) {
|
||||||
items = await createItems(materialData.items, material);
|
itemsList = await createItems(items, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
materialsData.push({
|
materialsData.push({
|
||||||
material,
|
material,
|
||||||
family: materialFamily,
|
family: materialFamily,
|
||||||
items,
|
items: itemsList,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +252,7 @@ module.exports = {
|
|||||||
|
|
||||||
warehouseSchema.warehouse = warehouse;
|
warehouseSchema.warehouse = warehouse;
|
||||||
if (!req.body.warehouse.zones) {
|
if (!req.body.warehouse.zones) {
|
||||||
const zones = createZones(req.body.warehouse.zones, warehouse);
|
const zones = await createZones(req.body.warehouse.zones, warehouse);
|
||||||
if (!zones) {
|
if (!zones) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -302,13 +288,10 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inventorySchema.inventory = inventory;
|
inventorySchema.inventory = inventory.toObject();
|
||||||
|
|
||||||
if (req.body.inventory.materials) {
|
if (req.body.inventory.materials) {
|
||||||
const materials = createMaterials(
|
const materials = await createMaterials(req.body.inventory.materials, inventory);
|
||||||
req.body.inventory.materials,
|
|
||||||
inventory
|
|
||||||
);
|
|
||||||
if (!materials) {
|
if (!materials) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user