/var/www/greso.tech/server/nsm/controllers/order/payment
Edit: /var/www/greso.tech/server/nsm/controllers/order/payment/edit.js (1684B)
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,
payTypeId,
cardType,
summ,
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 paymentEdit = await db.orderPayment.findOne({
// include: [{ model: db.role }],
where: { id: id }
})
if (!paymentEdit) {
throw new NotFound({ lang: req.user?.languageCode })
}
if (isSet(userId) && !isEmpty(userId)) {
paymentEdit.userId = req.user?.id
}
if (isSet(payTypeId) && !isEmpty(payTypeId)) {
paymentEdit.payTypeId = payTypeId
}
if (isSet(cardType) && !isEmpty(cardType)) {
paymentEdit.cardType = cardType
}
if (isSet(summ) && !isEmpty(summ)) {
paymentEdit.summ = summ
}
if (isSet(comment) && !isEmpty(comment)) {
paymentEdit.comment = comment
}
await paymentEdit.save()
const time = performance.now() - t1
return res.status(200).json({ status: 'success', id: paymentEdit.id, time })
} catch (err) {
next(err)
}
}
}