|
|
@ -537,13 +537,37 @@ exports.getCurrentSupplier = async (req, reply) => {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Get all users
|
|
|
|
// Get all suppliers
|
|
|
|
exports.getSuppliers1 = async (req, reply) => {
|
|
|
|
// exports.getSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
// const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
// const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
// const startindex = (page - 1) * limit;
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// await Supplier.find()
|
|
|
|
|
|
|
|
// .limit(limit)
|
|
|
|
|
|
|
|
// .skip(startindex)
|
|
|
|
|
|
|
|
// .exec()
|
|
|
|
|
|
|
|
// .then((docs) => {
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .catch((err) => {
|
|
|
|
|
|
|
|
// console.log(err);
|
|
|
|
|
|
|
|
// reply.send({ error: err });
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getSuppliers = async (req, reply) => {
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
|
|
|
|
const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await Supplier.find()
|
|
|
|
const friendRequests = await FriendRequest.find({ customerId });
|
|
|
|
|
|
|
|
const supplierIdsToExclude = friendRequests.map((request) => request.supplierId);
|
|
|
|
|
|
|
|
await Supplier.find({ supplierId: { $nin: supplierIdsToExclude } })
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
|
.skip(startindex)
|
|
|
|
.skip(startindex)
|
|
|
|
.exec()
|
|
|
|
.exec()
|
|
|
@ -559,15 +583,29 @@ exports.getSuppliers1 = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.getSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
// Get single user by ID
|
|
|
|
|
|
|
|
exports.getSingleSupplier = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const supplierId = req.params.supplierId;
|
|
|
|
|
|
|
|
const supplier = await Supplier.findOne({ supplierId: supplierId });
|
|
|
|
|
|
|
|
return supplier;
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getConnectedSuppliers = async (req, reply) => {
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
const startindex = (page - 1) * limit;
|
|
|
|
const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object
|
|
|
|
const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object
|
|
|
|
|
|
|
|
console.log(customerId,"HI")
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const friendRequests = await FriendRequest.find({ customerId });
|
|
|
|
const friendRequests = await FriendRequest.find({ customerId, status: "accepted" });
|
|
|
|
const supplierIdsToExclude = friendRequests.map((request) => request.supplierId);
|
|
|
|
console.log(friendRequests,customerId)
|
|
|
|
await Supplier.find({ supplierId: { $nin: supplierIdsToExclude } })
|
|
|
|
const supplierIdsToInclude = friendRequests.map((request) => request.supplierId);
|
|
|
|
|
|
|
|
await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
|
.skip(startindex)
|
|
|
|
.skip(startindex)
|
|
|
|
.exec()
|
|
|
|
.exec()
|
|
|
@ -584,13 +622,3 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get single user by ID
|
|
|
|
|
|
|
|
exports.getSingleSupplier = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const supplierId = req.params.supplierId;
|
|
|
|
|
|
|
|
const supplier = await Supplier.findOne({ supplierId: supplierId });
|
|
|
|
|
|
|
|
return supplier;
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|