diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 82059d51..48a69c0a 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -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 }); } }; + diff --git a/src/models/User.js b/src/models/User.js index 8bd09d8f..92301f63 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -62,7 +62,8 @@ const userSchema = new mongoose.Schema( emails: [{ email: String, verified: { type: Boolean, default: false } }], services: { password: { bcrypt: String } }, survey_status:{ type:String,default: "pending" }, - favorate_suppliers: [{ type:String,default: null }], + favorate_suppliers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Supplier", default: null }], + staff: {