|
|
|
@ -1151,17 +1151,20 @@ exports.getFavoriteSuppliers = async (req, reply) => {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const user = await User.findOne({ customerId })
|
|
|
|
|
.populate("favorate_suppliers") // This will now work properly
|
|
|
|
|
.exec();
|
|
|
|
|
const user = await User.findOne({ customerId }).exec();
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.status(404).send({ message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({ data: user.favorate_suppliers });
|
|
|
|
|
const suppliers = await Supplier.find({
|
|
|
|
|
supplierId: { $in: user.favorate_suppliers }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
reply.send({ data: suppliers });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|