|
|
@ -987,6 +987,36 @@ exports.getSingleSupplier = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getConnectedSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
// const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
// const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
// const friendRequests = await FriendRequest.find({
|
|
|
|
|
|
|
|
// customerId,
|
|
|
|
|
|
|
|
// status: "accepted",
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// // console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
// const supplierIdsToInclude = friendRequests.map(
|
|
|
|
|
|
|
|
// (request) => request.supplierId
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
|
|
|
|
// .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.getConnectedSuppliers = async (req, reply) => {
|
|
|
|
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;
|
|
|
@ -997,26 +1027,85 @@ exports.getConnectedSuppliers = async (req, reply) => {
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
|
status: "accepted",
|
|
|
|
status: "accepted",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
(request) => request.supplierId
|
|
|
|
(request) => request.supplierId
|
|
|
|
);
|
|
|
|
);
|
|
|
|
await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
|
|
|
|
|
|
|
|
const suppliers = await Supplier.find({
|
|
|
|
|
|
|
|
supplierId: { $in: supplierIdsToInclude }
|
|
|
|
|
|
|
|
})
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
|
.skip(startindex)
|
|
|
|
.skip(startindex)
|
|
|
|
.exec()
|
|
|
|
.exec();
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
const supplierIds = suppliers.map((supplier) => supplier.supplierId);
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
const profilePictures = await profilePictureSupplier.find({
|
|
|
|
console.log(err);
|
|
|
|
supplierId: { $in: supplierIds }
|
|
|
|
reply.send({ error: err });
|
|
|
|
}).exec();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = suppliers.map((supplier) => {
|
|
|
|
|
|
|
|
const profilePicture = profilePictures.find(
|
|
|
|
|
|
|
|
(picture) => picture.supplierId === supplier.supplierId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...supplier.toObject(),
|
|
|
|
|
|
|
|
picture: profilePicture ? profilePicture.picture : null,
|
|
|
|
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data, count: data.length });
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getPendingSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
// const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
// const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
// const friendRequests = await FriendRequest.find({
|
|
|
|
|
|
|
|
// customerId,
|
|
|
|
|
|
|
|
// status: ["pending"],
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// // console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
// const supplierIdsToInclude = friendRequests.map(
|
|
|
|
|
|
|
|
// (request) => request.supplierId
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// console.log(supplierIdsToInclude, "SUPLIERINCLUDE");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const timestamps = friendRequests.map(request => request.timestamp);
|
|
|
|
|
|
|
|
// console.log(timestamps, "timestamps");
|
|
|
|
|
|
|
|
// await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
|
|
|
|
// .limit(limit)
|
|
|
|
|
|
|
|
// .skip(startindex)
|
|
|
|
|
|
|
|
// .exec()
|
|
|
|
|
|
|
|
// .then((docs) => {
|
|
|
|
|
|
|
|
// const customerDataWithTimestamp = docs.map((doc, index) => ({
|
|
|
|
|
|
|
|
// ...doc._doc,
|
|
|
|
|
|
|
|
// timestamp: timestamps[index],
|
|
|
|
|
|
|
|
// }));
|
|
|
|
|
|
|
|
// reply.send({
|
|
|
|
|
|
|
|
// status_code: 200,
|
|
|
|
|
|
|
|
// data: customerDataWithTimestamp,
|
|
|
|
|
|
|
|
// count: docs.length,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// //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.getPendingSuppliers = async (req, reply) => {
|
|
|
|
exports.getPendingSuppliers = 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;
|
|
|
@ -1028,39 +1117,76 @@ exports.getPendingSuppliers = async (req, reply) => {
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
|
status: ["pending"],
|
|
|
|
status: ["pending"],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
(request) => request.supplierId
|
|
|
|
(request) => request.supplierId
|
|
|
|
);
|
|
|
|
);
|
|
|
|
console.log(supplierIdsToInclude, "SUPLIERINCLUDE");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const timestamps = friendRequests.map(request => request.timestamp);
|
|
|
|
const timestamps = friendRequests.map((request) => request.timestamp);
|
|
|
|
console.log(timestamps, "timestamps");
|
|
|
|
|
|
|
|
await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
const suppliers = await Supplier.find({
|
|
|
|
|
|
|
|
supplierId: { $in: supplierIdsToInclude },
|
|
|
|
|
|
|
|
})
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
|
.skip(startindex)
|
|
|
|
.skip(startindex)
|
|
|
|
.exec()
|
|
|
|
.exec();
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
const customerDataWithTimestamp = docs.map((doc, index) => ({
|
|
|
|
const supplierIds = suppliers.map((supplier) => supplier.supplierId);
|
|
|
|
...doc._doc,
|
|
|
|
|
|
|
|
|
|
|
|
const profilePictures = await profilePictureSupplier.find({
|
|
|
|
|
|
|
|
supplierId: { $in: supplierIds },
|
|
|
|
|
|
|
|
}).exec();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = suppliers.map((supplier, index) => {
|
|
|
|
|
|
|
|
const profilePicture = profilePictures.find(
|
|
|
|
|
|
|
|
(picture) => picture.supplierId === supplier.supplierId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...supplier.toObject(),
|
|
|
|
timestamp: timestamps[index],
|
|
|
|
timestamp: timestamps[index],
|
|
|
|
}));
|
|
|
|
picture: profilePicture ? profilePicture.picture : null,
|
|
|
|
reply.send({
|
|
|
|
};
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
data: customerDataWithTimestamp,
|
|
|
|
|
|
|
|
count: docs.length,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
//reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data, count: data.length });
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getRejectSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
// const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
|
|
|
// const page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
// const friendRequests = await FriendRequest.find({
|
|
|
|
|
|
|
|
// customerId,
|
|
|
|
|
|
|
|
// status: ["rejected"],
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// // console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
// const supplierIdsToInclude = friendRequests.map(
|
|
|
|
|
|
|
|
// (request) => request.supplierId
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// // console.log(supplierIdsToInclude)
|
|
|
|
|
|
|
|
// await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
|
|
|
|
// .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.getRejectSuppliers = async (req, reply) => {
|
|
|
|
exports.getRejectSuppliers = 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;
|
|
|
@ -1072,22 +1198,35 @@ exports.getRejectSuppliers = async (req, reply) => {
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
|
status: ["rejected"],
|
|
|
|
status: ["rejected"],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// console.log(friendRequests,customerId)
|
|
|
|
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
const supplierIdsToInclude = friendRequests.map(
|
|
|
|
(request) => request.supplierId
|
|
|
|
(request) => request.supplierId
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// console.log(supplierIdsToInclude)
|
|
|
|
|
|
|
|
await Supplier.find({ supplierId: { $in: supplierIdsToInclude } })
|
|
|
|
const suppliers = await Supplier.find({
|
|
|
|
|
|
|
|
supplierId: { $in: supplierIdsToInclude },
|
|
|
|
|
|
|
|
})
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
|
.skip(startindex)
|
|
|
|
.skip(startindex)
|
|
|
|
.exec()
|
|
|
|
.exec();
|
|
|
|
.then((docs) => {
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
const supplierIds = suppliers.map((supplier) => supplier.supplierId);
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
const profilePictures = await profilePictureSupplier.find({
|
|
|
|
console.log(err);
|
|
|
|
supplierId: { $in: supplierIds },
|
|
|
|
reply.send({ error: err });
|
|
|
|
}).exec();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = suppliers.map((supplier) => {
|
|
|
|
|
|
|
|
const profilePicture = profilePictures.find(
|
|
|
|
|
|
|
|
(picture) => picture.supplierId === supplier.supplierId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...supplier.toObject(),
|
|
|
|
|
|
|
|
picture: profilePicture ? profilePicture.picture : null,
|
|
|
|
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data, count: data.length });
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1095,6 +1234,7 @@ exports.getRejectSuppliers = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getPendingCustomers = async (req, reply) => {
|
|
|
|
exports.getPendingCustomers = 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;
|
|
|
|