/var/www/greso.tech/server/nsm/controllers/order/inventory/item/condition
Edit: /var/www/greso.tech/server/nsm/controllers/order/inventory/item/condition/delete.js (896B)
module.exports = function ({ db, logger }) {
const { NotFound, BadRequest } = require('../../../../../responseModels/errors')
const { isSet, isEmail, isPhone, isEmpty, minLength, isNumber } = require('../../../../../utils/validator.util')
return async (req, res, next) => {
logger.child({ path: req.path }).info()
let t1 = performance.now()
try {
const { id } = req.body
if (!isSet(id) || isEmpty(id)) {
throw new BadRequest({ code: 400, lang: req.user?.languageCode })
}
const condition = await db.inventoryItemsConditions.findOne({
where: { id: id }
})
if (!condition) {
throw new NotFound({ lang: req.user?.languageCode })
}
await db.inventoryItemsConditions.destroy({ where: { id: id } })
const time = performance.now() - t1
return res.status(200).json({ status: 'success', id: condition.id, time })
} catch (err) {
next(err)
}
}
}