/var/www/greso.tech/server/nsm/controllers/order/comment
Edit: /var/www/greso.tech/server/nsm/controllers/order/comment/delete.js (854B)
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 comment = await db.orderComment.findOne({
where: { id: id }
})
if (!comment) {
throw new NotFound({ lang: req.user?.languageCode })
}
await db.orderComment.destroy({ where: { id: id } })
const time = performance.now() - t1
return res.status(200).json({ status: 'success', id: comment.id, time })
} catch (err) {
next(err)
}
}
}