|
|
|
@ -1526,6 +1526,68 @@ exports.getuserRequestbookings = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// controllers/user.controller.js (or wherever your controllers live)
|
|
|
|
|
|
|
|
|
|
// const Supplier = require("../models/supplier.model"); // not needed here
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GET /api/getuserRequestbookingsforsupplier/:supplierId
|
|
|
|
|
* Returns bookings where this supplier was requested, showing only this supplier's sub-entry.
|
|
|
|
|
*/
|
|
|
|
|
exports.getuserRequestbookingsForSupplier = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supplierId } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!supplierId) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
status_code: 400,
|
|
|
|
|
message: "supplierId is required",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1) Find all bookings that include this supplier
|
|
|
|
|
const bookings = await RequestedBooking.find({
|
|
|
|
|
"requested_suppliers.supplierId": supplierId,
|
|
|
|
|
})
|
|
|
|
|
.sort({ createdAt: -1 })
|
|
|
|
|
.lean();
|
|
|
|
|
|
|
|
|
|
// 2) For each booking, expose only this supplier's subdocument
|
|
|
|
|
const data = bookings.map((b) => {
|
|
|
|
|
const mySupplierEntry = (b.requested_suppliers || []).find(
|
|
|
|
|
(s) => s.supplierId === supplierId
|
|
|
|
|
) || null;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
_id: b._id,
|
|
|
|
|
customerId: b.customerId,
|
|
|
|
|
type_of_water: b.type_of_water,
|
|
|
|
|
capacity: b.capacity,
|
|
|
|
|
quantity: b.quantity,
|
|
|
|
|
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 }
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: `Orders for supplier ${supplierId} fetched successfully`,
|
|
|
|
|
data,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mongoose = require('mongoose');
|
|
|
|
|