/var/www/qr4y.com/server/delivery/api/controllers/delivery_server
Edit: /var/www/qr4y.com/server/delivery/api/controllers/delivery_server/webhook.js (1224B)
const { NotFound } = require('../../responseModels/errors')
// const { isNumber } = require('../../utils/validator.util')
// const checkPermission = require('../../utils/checkPermission.util')
const { isSet, isEmpty, isArray, isNumber } = require('../../utils/validator.util')
module.exports = function ({ db, logger }) {
return async (req, res, next) => {
logger.child({ path: req.path, request: req.query }).info()
try {
// const { key, order_id, status, status_id } = req.body
let order = await SERVICES.OrderService.GetOrder(req.body.id)
if (!isSet(order)) {
throw new NotFound({ lang: req.user?.languageCode })
}
order.deliveryServerJson = JSON.stringify(req.body)
// order.deliveryServerJson = {
// order_id: order_id,
// status: status,
// status_id: status_id,
// }
await order.save()
await SERVICES.OrderService.StatusOrder(order)
if (order.deliveryServerId) {
await SERVICES.DeliveryService.UpdateOrder(order.id)
}
if (true) {
return res.status(200).json({
status: 'success',
order_id: order_id,
status: status,
})
} else {
throw new NotFound({ lang: req.user?.languageCode })
}
} catch (err) {
next(err)
}
}
}