-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #691 from OneCommunityGlobal/development
Backend Release to Main [1.30]
- Loading branch information
Showing
28 changed files
with
1,406 additions
and
791 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const bmConsumableController = function (BuildingConsumable) { | ||
const fetchBMConsumables = async (req, res) => { | ||
try { | ||
BuildingConsumable | ||
.find() | ||
.populate([ | ||
{ | ||
path: 'project', | ||
select: '_id name', | ||
}, | ||
{ | ||
path: 'itemType', | ||
select: '_id name unit', | ||
}, | ||
{ | ||
path: 'updateRecord', | ||
populate: { | ||
path: 'createdBy', | ||
select: '_id firstName lastName', | ||
}, | ||
}, | ||
{ | ||
path: 'purchaseRecord', | ||
populate: { | ||
path: 'requestedBy', | ||
select: '_id firstName lastName', | ||
}, | ||
}, | ||
]) | ||
.exec() | ||
.then(result => { | ||
res.status(200).send(result); | ||
}) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
|
||
return { | ||
fetchBMConsumables, | ||
}; | ||
}; | ||
|
||
module.exports = bmConsumableController; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,100 @@ | ||
const bmInventoryTypeController = function (InvType) { | ||
const fetchMaterialTypes = async (req, res) => { | ||
function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolType, EquipType) { | ||
async function fetchMaterialTypes(req, res) { | ||
try { | ||
InvType | ||
MatType | ||
.find() | ||
.exec() | ||
.then(result => res.status(200).send(result)) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
} | ||
|
||
async function addEquipmentType(req, res) { | ||
const { | ||
name, | ||
desc: description, | ||
fuel: fuelType, | ||
requestor: { requestorId }, | ||
} = req.body; | ||
try { | ||
EquipType | ||
.find({ name }) | ||
.then((result) => { | ||
if (result.length) { | ||
res.status(409).send(); | ||
} else { | ||
const newDoc = { | ||
category: 'Equipment', | ||
name, | ||
description, | ||
fuelType, | ||
createdBy: requestorId, | ||
}; | ||
EquipType | ||
.create(newDoc) | ||
.then(() => res.status(201).send()) | ||
.catch((error) => { | ||
if (error._message.includes('validation failed')) { | ||
res.status(400).send(error); | ||
} else { | ||
res.status(500).send(error); | ||
} | ||
}); | ||
} | ||
}) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
} | ||
const fetchSingleInventoryType = async (req, res) => { | ||
const { invtypeId } = req.params; | ||
try { | ||
const result = await InvType.findById(invtypeId).exec(); | ||
res.status(200).send(result); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}; | ||
|
||
const updateNameAndUnit = async (req, res) => { | ||
try { | ||
const { invtypeId } = req.params; | ||
const { name, unit } = req.body; | ||
|
||
const updateData = {}; | ||
|
||
if (name) { | ||
updateData.name = name; | ||
} | ||
|
||
if (unit) { | ||
updateData.unit = unit; | ||
} | ||
|
||
const updatedInvType = await InvType.findByIdAndUpdate( | ||
invtypeId, | ||
updateData, | ||
{ new: true, runValidators: true }, | ||
); | ||
|
||
if (!updatedInvType) { | ||
return res.status(404).json({ error: 'invType Material not found check Id' }); | ||
} | ||
|
||
res.status(200).json(updatedInvType); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}; | ||
return { | ||
fetchMaterialTypes, | ||
addEquipmentType, | ||
fetchSingleInventoryType, | ||
updateNameAndUnit, | ||
}; | ||
}; | ||
} | ||
|
||
module.exports = bmInventoryTypeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const bmToolController = (BuildingTool) => { | ||
const fetchSingleTool = async (req, res) => { | ||
const { toolId } = req.params; | ||
try { | ||
BuildingTool | ||
.findById(toolId) | ||
.populate([ | ||
{ | ||
path: 'itemType', | ||
select: '_id name description unit imageUrl category', | ||
}, | ||
{ | ||
path: 'userResponsible', | ||
select: '_id firstName lastName', | ||
}, | ||
{ | ||
path: 'purchaseRecord', | ||
populate: { | ||
path: 'requestedBy', | ||
select: '_id firstName lastName', | ||
}, | ||
}, | ||
{ | ||
path: 'updateRecord', | ||
populate: { | ||
path: 'createdBy', | ||
select: '_id firstName lastName', | ||
}, | ||
}, | ||
{ | ||
path: 'logRecord', | ||
populate: [{ | ||
path: 'createdBy', | ||
select: '_id firstName lastName', | ||
}, | ||
{ | ||
path: 'responsibleUser', | ||
select: '_id firstName lastName', | ||
}], | ||
}, | ||
]) | ||
.exec() | ||
.then(tool => res.status(200).send(tool)) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
return { fetchSingleTool }; | ||
}; | ||
|
||
module.exports = bmToolController; |
Oops, something went wrong.