master^2
Varun 5 months ago
parent 3ccc9686ac
commit 0c9fa6430e

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

@ -62,7 +62,8 @@ const userSchema = new mongoose.Schema(
emails: [{ email: String, verified: { type: Boolean, default: false } }], emails: [{ email: String, verified: { type: Boolean, default: false } }],
services: { password: { bcrypt: String } }, services: { password: { bcrypt: String } },
survey_status:{ type:String,default: "pending" }, survey_status:{ type:String,default: "pending" },
favorate_suppliers: [{ type:String,default: null }], favorate_suppliers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Supplier", default: null }],
staff: { staff: {

Loading…
Cancel
Save