|
|
|
@ -1886,4 +1886,54 @@ exports.estimationsget = async (req, reply) => {
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updatePaymentForBooking = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { bookingid } = req.params;
|
|
|
|
|
const { payment_mode, payment_reference_number } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!bookingid) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
status_code: 400,
|
|
|
|
|
message: 'bookingid (param) is required',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof payment_mode === 'undefined' && typeof payment_reference_number === 'undefined') {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
status_code: 400,
|
|
|
|
|
message: 'At least one of payment_mode or payment_reference_number must be provided in body',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const update = {};
|
|
|
|
|
if (typeof payment_mode !== 'undefined') update.payment_mode = payment_mode;
|
|
|
|
|
if (typeof payment_reference_number !== 'undefined') update.payment_reference_number = payment_reference_number;
|
|
|
|
|
|
|
|
|
|
const updated = await Tankerbooking.findOneAndUpdate(
|
|
|
|
|
{ bookingid },
|
|
|
|
|
{ $set: update },
|
|
|
|
|
{ new: true, runValidators: true }
|
|
|
|
|
).lean();
|
|
|
|
|
|
|
|
|
|
if (!updated) {
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
status_code: 404,
|
|
|
|
|
message: `No booking found with bookingid ${bookingid}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.code(200).send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: 'Payment info updated successfully',
|
|
|
|
|
data: updated,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('updatePaymentForBooking error:', err);
|
|
|
|
|
// keep using boom as you used earlier
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|