ashok 2 weeks ago
commit 20ea0152d9

@ -1552,11 +1552,32 @@ exports.getuserRequestbookingsForSupplier = async (req, reply) => {
.sort({ createdAt: -1 })
.lean();
// 2) For each booking, expose only this supplier's subdocument
if (!bookings.length) {
return reply.send({
status_code: 200,
message: `No orders found for supplier ${supplierId}`,
data: [],
});
}
// 2) Collect all unique customerIds
const customerIds = [...new Set(bookings.map((b) => b.customerId))];
// 3) Fetch user details for those customers
const users = await User.find({ customerId: { $in: customerIds } }).lean();
// 4) Build map for quick lookup
const userMap = users.reduce((acc, u) => {
acc[u.customerId] = u;
return acc;
}, {});
// 5) Format data with user info
const data = bookings.map((b) => {
const mySupplierEntry = (b.requested_suppliers || []).find(
(s) => s.supplierId === supplierId
) || null;
const mySupplierEntry =
(b.requested_suppliers || []).find(
(s) => s.supplierId === supplierId
) || null;
return {
_id: b._id,
@ -1567,13 +1588,15 @@ exports.getuserRequestbookingsForSupplier = async (req, reply) => {
total_required_capacity: b.total_required_capacity,
date: b.date,
time: b.time,
// booking-wide status (e.g., pending/confirmed/cancelled)
booking_status: b.status,
createdAt: b.createdAt,
updatedAt: b.updatedAt,
// only the supplier's own requested_suppliers entry
my_supplier_entry: mySupplierEntry, // { supplierId, quoted_amount, time, status }
// supplier-specific entry
my_supplier_entry: mySupplierEntry,
// attach full user details here
customer_details: userMap[b.customerId] || null,
};
});
@ -1589,6 +1612,7 @@ exports.getuserRequestbookingsForSupplier = async (req, reply) => {
};
exports.getuserRequestbookingsforplansforsupplier = async (req, reply) => {
try {
const { supplierId } = req.params;

Loading…
Cancel
Save