add filed profilepicture in get all suppliers

master
Bhaskara Kishore 2 years ago
parent 68036ab6d6
commit 834e68e2fb

@ -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);
}

Loading…
Cancel
Save