|
|
@ -952,7 +952,7 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
time,
|
|
|
|
time,
|
|
|
|
price_from,
|
|
|
|
price_from,
|
|
|
|
price_to,
|
|
|
|
price_to,
|
|
|
|
radius_from, // even if sent we will not apply now
|
|
|
|
radius_from,
|
|
|
|
radius_to,
|
|
|
|
radius_to,
|
|
|
|
rating_from,
|
|
|
|
rating_from,
|
|
|
|
rating_to
|
|
|
|
rating_to
|
|
|
@ -977,7 +977,6 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
tankerBookings.map(booking => `${booking.supplierId}_${booking.tankerName}`)
|
|
|
|
tankerBookings.map(booking => `${booking.supplierId}_${booking.tankerName}`)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 🟢 Initial tanker query condition
|
|
|
|
|
|
|
|
const tankerQuery = {};
|
|
|
|
const tankerQuery = {};
|
|
|
|
|
|
|
|
|
|
|
|
if (type_of_water && type_of_water.trim() !== "") {
|
|
|
|
if (type_of_water && type_of_water.trim() !== "") {
|
|
|
@ -986,7 +985,6 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
let tankers = await Tanker.find(tankerQuery);
|
|
|
|
let tankers = await Tanker.find(tankerQuery);
|
|
|
|
|
|
|
|
|
|
|
|
// 🟢 Apply price filter only if both price_from and price_to are given (not empty)
|
|
|
|
|
|
|
|
if (price_from && price_to) {
|
|
|
|
if (price_from && price_to) {
|
|
|
|
tankers = tankers.filter(tanker => {
|
|
|
|
tankers = tankers.filter(tanker => {
|
|
|
|
const tankerPrice = parsePrice(tanker.price);
|
|
|
|
const tankerPrice = parsePrice(tanker.price);
|
|
|
@ -994,13 +992,11 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 🟢 Exclude booked tankers
|
|
|
|
|
|
|
|
tankers = tankers.filter(tanker => {
|
|
|
|
tankers = tankers.filter(tanker => {
|
|
|
|
const key = `${tanker.supplierId}_${tanker.tankerName}`;
|
|
|
|
const key = `${tanker.supplierId}_${tanker.tankerName}`;
|
|
|
|
return !bookedTankerSet.has(key);
|
|
|
|
return !bookedTankerSet.has(key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 🟢 Group tankers by supplierId
|
|
|
|
|
|
|
|
const supplierTankerMap = {};
|
|
|
|
const supplierTankerMap = {};
|
|
|
|
for (let tanker of tankers) {
|
|
|
|
for (let tanker of tankers) {
|
|
|
|
if (!supplierTankerMap[tanker.supplierId]) {
|
|
|
|
if (!supplierTankerMap[tanker.supplierId]) {
|
|
|
@ -1017,7 +1013,6 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
0
|
|
|
|
0
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 🟢 Apply capacity filtering only if both are given
|
|
|
|
|
|
|
|
if (requestedCapacity > 0 && requestedQuantity > 0) {
|
|
|
|
if (requestedCapacity > 0 && requestedQuantity > 0) {
|
|
|
|
if (totalAvailableCapacity < totalRequiredCapacity) {
|
|
|
|
if (totalAvailableCapacity < totalRequiredCapacity) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -1040,11 +1035,27 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
const isConnected = friendRequest && friendRequest.status === "accepted";
|
|
|
|
const isConnected = friendRequest && friendRequest.status === "accepted";
|
|
|
|
const isFavorite = favorateSuppliers.includes(supplierObj.supplierId);
|
|
|
|
const isFavorite = favorateSuppliers.includes(supplierObj.supplierId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 🔥 Now check RequestedBooking collection
|
|
|
|
|
|
|
|
const requestedBookingRecord = await RequestedBooking.findOne({
|
|
|
|
|
|
|
|
customerId: customerId,
|
|
|
|
|
|
|
|
"requested_suppliers.supplierId": supplierObj.supplierId
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let requestedBooking = { status: false };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (requestedBookingRecord) {
|
|
|
|
|
|
|
|
requestedBooking = {
|
|
|
|
|
|
|
|
status: true,
|
|
|
|
|
|
|
|
time: requestedBookingRecord.time
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
suppliers.push({
|
|
|
|
suppliers.push({
|
|
|
|
supplier: supplierData,
|
|
|
|
supplier: supplierData,
|
|
|
|
tankers: supplierObj.tankers,
|
|
|
|
tankers: supplierObj.tankers,
|
|
|
|
isConnected: isConnected,
|
|
|
|
isConnected: isConnected,
|
|
|
|
isFavorite: isFavorite
|
|
|
|
isFavorite: isFavorite,
|
|
|
|
|
|
|
|
requestedBooking: requestedBooking
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|