|
|
|
@ -13,7 +13,7 @@ const { Tankerbooking} = require("../models/tankers")
|
|
|
|
|
const {EstimationOrder} = require("../models/store");
|
|
|
|
|
|
|
|
|
|
// Get Data Models
|
|
|
|
|
const { RequestedBooking,Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
|
|
|
|
|
const { RecurringRequestedBooking,RequestedBooking,Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
|
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture, AddTeamMembers,Cart} = require('../models/User')
|
|
|
|
|
//const User = require("../models/User");
|
|
|
|
|
|
|
|
|
@ -1589,6 +1589,59 @@ exports.getuserRequestbookingsForSupplier = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getuserRequestbookingsforplansforsupplier = 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 RecurringRequestedBooking.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');
|
|
|
|
|
|
|
|
|
|