|
|
|
@ -731,6 +731,46 @@ exports.changePassword = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.addingfavoratesupplier = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
const { supplierId } = req.query;
|
|
|
|
|
|
|
|
|
|
if (!supplierId) {
|
|
|
|
|
return reply.code(400).send({ status_code: 400, message: "supplierId is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find user
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.code(404).send({ status_code: 404, message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add supplierId to favorate_suppliers if not already there
|
|
|
|
|
if (!user.favorate_suppliers.includes(supplierId)) {
|
|
|
|
|
user.favorate_suppliers.push(supplierId);
|
|
|
|
|
await user.save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch FriendRequest status
|
|
|
|
|
const friendRequest = await FriendRequest.findOne({ customerId, supplierId });
|
|
|
|
|
const status = friendRequest ? friendRequest.status : "not_requested";
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Supplier added to favorites successfully",
|
|
|
|
|
data: {
|
|
|
|
|
customerId,
|
|
|
|
|
supplierId,
|
|
|
|
|
favorate_suppliers: user.favorate_suppliers,
|
|
|
|
|
status,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
reply.status(500).send({ status_code: 500, message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.forgotPasswordSupplier = async (req, reply) => {
|
|
|
|
@ -890,58 +930,7 @@ exports.deleteTeamMember = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.addingfavoratesupplier = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
const { supplierId } = req.query;
|
|
|
|
|
|
|
|
|
|
if (!supplierId) {
|
|
|
|
|
return reply.code(400).send({ status_code: 400, message: "supplierId is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find supplier by supplierId string to get the _id
|
|
|
|
|
const supplier = await Supplier.findOne({ supplierId });
|
|
|
|
|
if (!supplier) {
|
|
|
|
|
return reply.code(404).send({ status_code: 404, message: "Supplier not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find user
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.code(404).send({ status_code: 404, message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add supplier._id to favorate_suppliers if not already present
|
|
|
|
|
const supplierObjectId = supplier._id.toString();
|
|
|
|
|
const isAlreadyFavorite = user.favorate_suppliers.some(
|
|
|
|
|
(id) => id.toString() === supplierObjectId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!isAlreadyFavorite) {
|
|
|
|
|
user.favorate_suppliers.push(supplier._id);
|
|
|
|
|
await user.save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch FriendRequest status
|
|
|
|
|
const friendRequest = await FriendRequest.findOne({ customerId, supplierId });
|
|
|
|
|
const status = friendRequest ? friendRequest.status : "not_requested";
|
|
|
|
|
|
|
|
|
|
// Send response
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Supplier added to favorites successfully",
|
|
|
|
|
data: {
|
|
|
|
|
customerId,
|
|
|
|
|
supplierId,
|
|
|
|
|
favorate_suppliers: user.favorate_suppliers,
|
|
|
|
|
status,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
reply.status(500).send({ status_code: 500, message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.editFavoriteSupplier = async (req, reply) => {
|
|
|
|
|