diff --git a/package-lock.json b/package-lock.json index b38605eea..8cdef314d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26351,4 +26351,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/src/controllers/bmdashboard/bmInventoryTypeController.js b/src/controllers/bmdashboard/bmInventoryTypeController.js index c1cfcdc98..0dda84de6 100644 --- a/src/controllers/bmdashboard/bmInventoryTypeController.js +++ b/src/controllers/bmdashboard/bmInventoryTypeController.js @@ -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; @@ -246,6 +293,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp fetchSingleInventoryType, updateNameAndUnit, addMaterialType, + addConsumableType, fetchInvUnitsFromJson, fetchInventoryByType, }; diff --git a/src/controllers/profileInitialSetupController.js b/src/controllers/profileInitialSetupController.js index cd40e356c..7e1d5ed0a 100644 --- a/src/controllers/profileInitialSetupController.js +++ b/src/controllers/profileInitialSetupController.js @@ -376,4 +376,4 @@ const profileInitialSetupController = function ( }; }; -module.exports = profileInitialSetupController; +module.exports = profileInitialSetupController; \ No newline at end of file diff --git a/src/controllers/reasonSchedulingController.js b/src/controllers/reasonSchedulingController.js index a227e7f3e..67162abe1 100644 --- a/src/controllers/reasonSchedulingController.js +++ b/src/controllers/reasonSchedulingController.js @@ -395,4 +395,4 @@ module.exports = { getSingleReason, patchReason, deleteReason, -}; +}; \ No newline at end of file diff --git a/src/helpers/reporthelper.js b/src/helpers/reporthelper.js index 9342b6136..6e874035f 100644 --- a/src/helpers/reporthelper.js +++ b/src/helpers/reporthelper.js @@ -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: { diff --git a/src/models/bmdashboard/buildingInventoryType.js b/src/models/bmdashboard/buildingInventoryType.js index 821f3e57b..9173bf5cc 100644 --- a/src/models/bmdashboard/buildingInventoryType.js +++ b/src/models/bmdashboard/buildingInventoryType.js @@ -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 }, })); //--------------------------- diff --git a/src/models/userProfile.js b/src/models/userProfile.js index 7f1d95d7a..af022dc23 100644 --- a/src/models/userProfile.js +++ b/src/models/userProfile.js @@ -258,4 +258,4 @@ module.exports = mongoose.model( 'userProfile', userProfileSchema, 'userProfiles', -); +); \ No newline at end of file diff --git a/src/routes/bmdashboard/bmInventoryTypeRouter.js b/src/routes/bmdashboard/bmInventoryTypeRouter.js index 62e566433..9f3803594 100644 --- a/src/routes/bmdashboard/bmInventoryTypeRouter.js +++ b/src/routes/bmdashboard/bmInventoryTypeRouter.js @@ -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); diff --git a/src/utilities/logPermissionChangeByAccount.js b/src/utilities/logPermissionChangeByAccount.js index 3c2198933..e2505bf4c 100644 --- a/src/utilities/logPermissionChangeByAccount.js +++ b/src/utilities/logPermissionChangeByAccount.js @@ -62,4 +62,4 @@ const logPermissionChangeByAccount = async (requestBody) => { } }; -module.exports = changedPermissionsLogger; +module.exports = changedPermissionsLogger; \ No newline at end of file