This commit is contained in:
Sathishkumar Krishnan
2021-12-31 10:15:21 +05:30
parent 873aee4fac
commit f55b825d85

View File

@@ -34,7 +34,7 @@ module.exports = {
createItem: async (req, res, next) => {
let material;
if (req.body.materialId && mongoose.isValidObjectId(req.body.materialId)) {
material = await Material.findById(material);
material = await Material.findById(req.body.materialId);
}
const item = {
commonName: req.body.commonName,
@@ -50,13 +50,15 @@ module.exports = {
countPerPallet: req.body.countPerPallet,
countPerPalletPackage: req.body.countPerPalletPackage,
customAttributes: req.body.customAttributes,
material,
material: material,
};
if (Object.values(item).every((_) => _)) {
res.status(400).send("Missing params param");
for (const key of Object.keys(item)) {
if (item[key] === undefined) {
res.status(400).send({ success: false, error: `Missing required param: "${key}"` });
return;
}
}
try {
const itemData = new Item(item);
@@ -77,6 +79,10 @@ module.exports = {
*/
updateItemByID: async (req, res, next) => {
const { id } = req.params;
let material;
if (req.body.materialId && mongoose.isValidObjectId(req.body.materialId)) {
material = await Material.findById(req.body.materialId);
}
if (!id) {
res.status(400).send("Missing id param");
@@ -97,6 +103,7 @@ module.exports = {
countPerPallet: req.body.countPerPallet,
countPerPalletPackage: req.body.countPerPalletPackage,
customAttributes: req.body.customAttributes,
material: material,
};
try {
@@ -165,6 +172,7 @@ module.exports = {
formalName: 1,
description: 1,
manufacturer: 1,
material: 1,
size: 1,
color: 1,
type: 1,
@@ -176,7 +184,7 @@ module.exports = {
customAttributes: 1,
},
{ skip: page * perPage, limit: perPage }
);
).populate({ path: "material" });
if (!itemData) {
res.status(404);
return;