master^2
Varun 5 months ago
parent 518c0b5c2a
commit 07f2011e25

@ -1151,20 +1151,31 @@ exports.getFavoriteSuppliers = async (req, reply) => {
const { customerId } = req.params; const { customerId } = req.params;
try { try {
const user = await User.findOne({ customerId }).exec(); // Find the user by customerId
const user = await User.findOne({ customerId });
if (!user) { if (!user) {
return reply.status(404).send({ message: "User not found" }); return reply.status(404).send({ status_code: 404, message: "User not found" });
} }
const supplierIds = user.favorate_suppliers || [];
// Get full supplier details for those supplierIds
const suppliers = await Supplier.find({ const suppliers = await Supplier.find({
supplierId: { $in: user.favorate_suppliers } supplierId: { $in: supplierIds }
}).exec();
reply.send({
status_code: 200,
data: suppliers,
count: suppliers.length
}); });
reply.send({ data: suppliers });
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); console.error("Error fetching favorite suppliers:", err);
reply.status(500).send({ status_code: 500, message: "Internal server error" });
} }
}; };

@ -1043,5 +1043,6 @@ fastify.route({
next(); next();
}; };

Loading…
Cancel
Save