/var/www/greso.tech/server/nsm/controllers/order/comment
Edit: /var/www/greso.tech/server/nsm/controllers/order/comment/edit.js (1330B)
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, request: req.query }).info()
let t1 = performance.now()
try {
var {
id,
orderId,
userId,
comment,
} = req.body
if (!isSet(id) || isEmpty(id)) {
throw new BadRequest({ code: 400, lang: req.user?.languageCode })
}
if (!isSet(orderId) || isEmpty(orderId)) {
throw new BadRequest({ code: 400, lang: req.user?.languageCode })
}
if (!isSet(comment) || isEmpty(comment)) {
throw new BadRequest({
code: 2038,
lang: req.user?.languageCode
})
}
const commentEdit = await db.orderComment.findOne({
// include: [{ model: db.role }],
where: { id: id }
})
if (!commentEdit) {
throw new NotFound({ lang: req.user?.languageCode })
}
if (isSet(userId) && !isEmpty(userId)) {
commentEdit.userId = userId
}
commentEdit.comment = comment
await commentEdit.save()
const time = performance.now() - t1
return res.status(200).json({ status: 'success', id: commentEdit.id, time })
} catch (err) {
next(err)
}
}
}