Skip to content

Commit

Permalink
git conflicts , type-item mongoose key name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishala09 committed Jan 6, 2024
2 parents 0888853 + 15af5fc commit e19256d
Show file tree
Hide file tree
Showing 20 changed files with 1,903 additions and 1,390 deletions.
91 changes: 86 additions & 5 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
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;
52 changes: 52 additions & 0 deletions src/controllers/bmdashboard/bmToolController.js
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;
Loading

0 comments on commit e19256d

Please sign in to comment.