Skip to content

Commit

Permalink
Merge pull request #737 from OneCommunityGlobal/ilya_consumables_add_…
Browse files Browse the repository at this point in the history
…page

Ilya consumables add page
  • Loading branch information
one-community authored Apr 1, 2024
2 parents b3599a4 + 3012439 commit e84b647
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,53 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
}
}


async function addConsumableType(req, res) {
const {
name,
description,
unit,
size,
requestor: { requestorId },
} = req.body;

try {
ConsType
.find({ name })
.then((result) => {
if (result.length) {
res.status(409).send('Oops!! Consumable already exists!');
} else {
const newDoc = {
category: 'Consumable',
name,
description,
unit,
size,
createdBy: requestorId,
};
ConsType
.create(newDoc)
.then((results) => {
res.status(201).send(results);
})
.catch((error) => {
if (error._message.includes('validation failed')) {
res.status(400).send(error.errors.unit.message);
} else {
res.status(500).send(error);
}
});
}
})
.catch((error) => {
res.status(500).send(error);
});
} catch (error) {
res.status(500).send(error);
}
}

async function fetchInventoryByType(req, res) {
const { type } = req.params;
let SelectedType = InvType;
Expand Down Expand Up @@ -246,6 +293,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
fetchSingleInventoryType,
updateNameAndUnit,
addMaterialType,
addConsumableType,
fetchInvUnitsFromJson,
fetchInventoryByType,
};
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/profileInitialSetupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,4 @@ const profileInitialSetupController = function (
};
};

module.exports = profileInitialSetupController;
module.exports = profileInitialSetupController;
2 changes: 1 addition & 1 deletion src/controllers/reasonSchedulingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,4 @@ module.exports = {
getSingleReason,
patchReason,
deleteReason,
};
};
6 changes: 3 additions & 3 deletions src/helpers/reporthelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ const reporthelper = function () {
},
},
teamCode: {
$ifNull: ["$teamCode", ""],
$ifNull: ['$teamCode', ''],
},
timeOffFrom: {
$ifNull: ["$timeOffFrom", null],
$ifNull: ['$timeOffFrom', null],
},
timeOffTill: {
$ifNull: ["$timeOffTill", null],
$ifNull: ['$timeOffTill', null],
},
role: 1,
weeklySummaries: {
Expand Down
3 changes: 2 additions & 1 deletion src/models/bmdashboard/buildingInventoryType.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const materialType = invTypeBase.discriminator('material_type', new mongoose.Sch

const consumableType = invTypeBase.discriminator('consumable_type', new mongoose.Schema({
category: { type: String, enum: ['Consumable'] },
size: { type: String, required: true },
unit: { type: String, required: true },
size: { type: String, required: false },
}));

//---------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/models/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ module.exports = mongoose.model(
'userProfile',
userProfileSchema,
'userProfiles',
);
);
3 changes: 3 additions & 0 deletions src/routes/bmdashboard/bmInventoryTypeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const routes = function (baseInvType, matType, consType, reusType, toolType, equ
inventoryTypeRouter.route('/invtypes/material')
.post(controller.addMaterialType);

inventoryTypeRouter.route('/consumables')
.post(controller.addConsumableType);

inventoryTypeRouter.route('/invtypes/tools')
.get(controller.fetchToolTypes);

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/logPermissionChangeByAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ const logPermissionChangeByAccount = async (requestBody) => {
}
};

module.exports = changedPermissionsLogger;
module.exports = changedPermissionsLogger;

0 comments on commit e84b647

Please sign in to comment.