From dd5ce755273234fa76ae1bc908bdcca19c17c3e0 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 3 Jul 2025 14:20:05 +0530 Subject: [PATCH] changes in user acceptance for tanker booking --- src/controllers/userController.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/controllers/userController.js b/src/controllers/userController.js index bcccb50f..e4d361f9 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -1356,6 +1356,7 @@ exports.getuserRequestbookings = async (req, reply) => { +const mongoose = require('mongoose'); exports.acceptRequestedBooking = async (req, reply) => { @@ -1405,8 +1406,25 @@ exports.getuserRequestbookings = async (req, reply) => { if (!matchedSupplier.quoted_amount) { return reply.code(400).send({ message: "Quoted amount missing for this supplier" }); } +requestedBooking.requested_suppliers = requestedBooking.requested_suppliers.filter( + s => s.supplierId !== supplierId +); + +// ✅ Optional: Mark booking as fully processed if no more suppliers remain +if (requestedBooking.requested_suppliers.length === 0) { + requestedBooking.status = 'processed'; +} + +await requestedBooking.save(); + +// Format: ARM + YYYYMMDD + random digit (0–9) +const today = new Date(); +const datePart = today.toISOString().slice(0, 10).replace(/-/g, ''); // YYYYMMDD +const randomDigit = Math.floor(Math.random() * 10); // 0–9 +const bookingId = `ARM${datePart}${randomDigit}`; const newBooking = new Tankerbooking({ + bookingid: bookingId, customerId: customer.customerId, customerName: customer.profile.firstName, customerPhone: customer.phone,