fix: added icon_slug to inventory

This commit is contained in:
Sathishkumar Krishnan
2022-02-27 15:53:22 +05:30
parent aa158a73c0
commit 9fe979ad2c
2 changed files with 16 additions and 12 deletions

View File

@@ -64,11 +64,11 @@ module.exports = {
* Create a Inventory * Create a Inventory
*/ */
createInventory: async (req, res, next) => { createInventory: async (req, res, next) => {
let { name, policies, widgetName } = req.body; let { name, policies, widgetName, icon_slug } = req.body;
const image = req.file; const image = req.file;
if (!(name && widgetName)) { if (!(name && widgetName && icon_slug)) {
res.status(400).send("Missing params name"); res.status(400).send("Missing params");
return; return;
} }
const preferredLocations = []; const preferredLocations = [];
@@ -93,13 +93,11 @@ module.exports = {
name, name,
widgetName, widgetName,
policies: verifiedPolicies, policies: verifiedPolicies,
icon_slug,
}); });
if (image) { if (image) {
const url = await S3.uploadFile( const url = await S3.uploadFile(`inventory/${inventoryData._id.toString()}.${image.originalname.split(".").slice(-1).pop()}`, image.path);
`inventory/${inventoryData._id.toString()}.${image.originalname.split(".").slice(-1).pop()}`,
image.path
);
inventoryData.image_url = url; inventoryData.image_url = url;
} }
@@ -133,7 +131,7 @@ module.exports = {
res.status(400).send("Inventory not found"); res.status(400).send("Inventory not found");
return; return;
} }
let { name, policies, widgetName } = req.body; let { name, policies, widgetName, icon_slug } = req.body;
if (name) { if (name) {
inventory.name = name; inventory.name = name;
} }
@@ -142,6 +140,9 @@ module.exports = {
inventory.widgetName = widgetName; inventory.widgetName = widgetName;
} }
if (icon_slug) {
inventory.icon_slug = icon_slug;
}
if (!policies) { if (!policies) {
policies = {}; policies = {};
} }
@@ -159,10 +160,7 @@ module.exports = {
inventory.policies = verifiedPolicies; inventory.policies = verifiedPolicies;
const image = req.file; const image = req.file;
if (image) { if (image) {
const url = await S3.uploadFile( const url = await S3.uploadFile(`inventory/${inventory._id.toString()}.${image.originalname.split(".").slice(-1).pop()}`, image.path);
`inventory/${inventory._id.toString()}.${image.originalname.split(".").slice(-1).pop()}`,
image.path
);
inventory.image_url = url; inventory.image_url = url;
} }

View File

@@ -12,6 +12,12 @@ const schema = new mongoose.Schema(
type: String, type: String,
trim: true, trim: true,
}, },
icon_slug: {
type: String,
trim: true,
required: true,
// enum: []
},
widgetName: { widgetName: {
type: String, type: String,
required: true, required: true,