|
|
@ -890,6 +890,102 @@ 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 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";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.editFavoriteSupplier = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
const { oldSupplierId, newSupplierId } = req.query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
|
|
|
if (!user) return reply.code(404).send({ status_code: 404, message: "User not found" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const index = user.favorate_suppliers.indexOf(oldSupplierId);
|
|
|
|
|
|
|
|
if (index === -1)
|
|
|
|
|
|
|
|
return reply.code(400).send({ status_code: 400, message: "Old supplier not found in favorites" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.favorate_suppliers[index] = newSupplierId;
|
|
|
|
|
|
|
|
await user.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
message: "Favorite supplier updated",
|
|
|
|
|
|
|
|
data: user.favorate_suppliers,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deleteFavoriteSupplier = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
const { supplierId } = req.query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
|
|
|
if (!user) return reply.code(404).send({ status_code: 404, message: "User not found" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const initialLength = user.favorate_suppliers.length;
|
|
|
|
|
|
|
|
user.favorate_suppliers = user.favorate_suppliers.filter(id => id !== supplierId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (user.favorate_suppliers.length === initialLength)
|
|
|
|
|
|
|
|
return reply.code(400).send({ status_code: 400, message: "Supplier not found in favorites" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await user.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
message: "Favorite supplier removed",
|
|
|
|
|
|
|
|
data: user.favorate_suppliers,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateTeamMember = async (req, reply) => {
|
|
|
|
exports.updateTeamMember = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
var customerId = req.params.customerId;
|
|
|
|
var customerId = req.params.customerId;
|
|
|
|