|
|
|
@ -1080,6 +1080,46 @@ if (isValidPrice(price_from) && isValidPrice(price_to)) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET SUPPLIERS (simple): only needs customerId; no tanker checks
|
|
|
|
|
exports.getSupplierswithoutbooking = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
// 1) Load customer to read favorites
|
|
|
|
|
const customer = await User.findOne({ customerId }, { favorate_suppliers: 1, _id: 0 });
|
|
|
|
|
if (!customer) {
|
|
|
|
|
return reply.code(404).send({ status_code: 404, message: "Customer not found" });
|
|
|
|
|
}
|
|
|
|
|
const favoriteSet = new Set(customer.favorate_suppliers || []);
|
|
|
|
|
|
|
|
|
|
// 2) Load all suppliers
|
|
|
|
|
const suppliers = await Supplier.find({}); // add projection if you want to slim payload
|
|
|
|
|
|
|
|
|
|
// 3) Find accepted connections for this customer across ALL suppliers in one go
|
|
|
|
|
const supplierIds = suppliers.map(s => s.supplierId).filter(Boolean);
|
|
|
|
|
const acceptedReqs = await FriendRequest.find(
|
|
|
|
|
{ customerId, supplierId: { $in: supplierIds }, status: "accepted" },
|
|
|
|
|
{ supplierId: 1, _id: 0 }
|
|
|
|
|
);
|
|
|
|
|
const connectedSet = new Set(acceptedReqs.map(r => r.supplierId));
|
|
|
|
|
|
|
|
|
|
// 4) Build response
|
|
|
|
|
const result = suppliers.map(s => ({
|
|
|
|
|
supplier: s,
|
|
|
|
|
isFavorite: favoriteSet.has(s.supplierId),
|
|
|
|
|
isConnected: connectedSet.has(s.supplierId),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return reply.send({ status_code: 200, suppliers: result });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
return reply.code(500).send({
|
|
|
|
|
status_code: 500,
|
|
|
|
|
message: "Something went wrong",
|
|
|
|
|
error: err.message,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createRequestedBooking = async (req, reply) => {
|
|
|
|
|