|
|
|
@ -937,6 +937,8 @@ exports.getCurrentSupplier = async (req, reply) => {
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getSuppliers = async (req, reply) => {
|
|
|
|
|
const limit = parseInt(req.query.limit) || 100;
|
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
@ -947,17 +949,27 @@ exports.getSuppliers = async (req, reply) => {
|
|
|
|
|
const supplierIdsToExclude = friendRequests.map(
|
|
|
|
|
(request) => request.supplierId
|
|
|
|
|
);
|
|
|
|
|
await Supplier.find({ supplierId: { $nin: supplierIdsToExclude } })
|
|
|
|
|
const suppliers = await Supplier.find({ supplierId: { $nin: supplierIdsToExclude } })
|
|
|
|
|
.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 });
|
|
|
|
|
});
|
|
|
|
|
.exec();
|
|
|
|
|
|
|
|
|
|
const supplierIds = suppliers.map((supplier) => supplier.supplierId);
|
|
|
|
|
const profilePictures = await profilePictureSupplier.find({
|
|
|
|
|
supplierId: { $in: supplierIds },
|
|
|
|
|
}).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) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|