|
|
|
@ -984,48 +984,7 @@ exports.deleteFavoriteSupplier = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getFavoriteSuppliers = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
// Get user's favorite suppliers list
|
|
|
|
|
const user = await User.findOne({ customerId }, 'favorate_suppliers');
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.code(404).send({ status_code: 404, message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const favorateSupplierIds = user.favorate_suppliers || [];
|
|
|
|
|
if (favorateSupplierIds.length === 0) {
|
|
|
|
|
return reply.send({ status_code: 200, data: [], count: 0 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch supplier details
|
|
|
|
|
const suppliers = await Supplier.find({
|
|
|
|
|
supplierId: { $in: favorateSupplierIds }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Fetch profile pictures
|
|
|
|
|
const profilePictures = await profilePictureSupplier.find({
|
|
|
|
|
supplierId: { $in: favorateSupplierIds }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Combine data
|
|
|
|
|
const data = suppliers.map((supplier) => {
|
|
|
|
|
const profilePicture = profilePictures.find(
|
|
|
|
|
(pic) => pic.supplierId === supplier.supplierId
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
...supplier.toObject(),
|
|
|
|
|
picture: profilePicture ? profilePicture.picture : null,
|
|
|
|
|
favorate: true,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data, count: data.length });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1186,26 +1145,7 @@ exports.blockStaff = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addFavoriteSupplier = async (req, reply) => {
|
|
|
|
|
const { customerId, supplierId } = req.body;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.status(404).send({ message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!user.favorate_suppliers.includes(supplierId)) {
|
|
|
|
|
user.favorate_suppliers.push(supplierId);
|
|
|
|
|
await user.save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({ message: "Supplier added to favorites", data: user.favorate_suppliers });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getFavoriteSuppliers = async (req, reply) => {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
@ -1225,24 +1165,3 @@ exports.getFavoriteSuppliers = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.removeFavoriteSupplier = async (req, reply) => {
|
|
|
|
|
const { customerId, supplierId } = req.params;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.status(404).send({ message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.favorate_suppliers = user.favorate_suppliers.filter(
|
|
|
|
|
(id) => id.toString() !== supplierId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await user.save();
|
|
|
|
|
|
|
|
|
|
reply.send({ message: "Supplier removed from favorites", data: user.favorate_suppliers });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|