connected customers

master
Bhaskara Kishore 3 years ago
parent 7ebe3e0963
commit 78bfa5afcc

@ -883,3 +883,30 @@ exports.getPendingCustomers = async (req, reply) => {
}; };
exports.getconnectedCustomers = async (req, reply) => {
const limit = parseInt(req.query.limit) || 100;
const page = parseInt(req.query.page) || 1;
const startindex = (page - 1) * limit;
const supplierId = req.params.supplierId; // Assuming you have already authenticated the user and stored their ID in the request object
try {
const friendRequests = await FriendRequest.find({ supplierId, status: ["accepted"] });
console.log(friendRequests,supplierId, "su....")
const supplierIdsToInclude = friendRequests.map((request) => request.customerId);
console.log(supplierIdsToInclude, "supplierIdsToInclude..")
await User.find({ customerId: { $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);
}
};

@ -107,6 +107,31 @@ module.exports = function (fastify, opts, next) {
handler: validationHandler.getPendingCustomers, handler: validationHandler.getPendingCustomers,
}); });
fastify.get("/api/connectedCustomers/:supplierId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All connected Customers",
summary: "This is for to Get All connected Customers",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getconnectedCustomers,
});
fastify.post("/api/supplierlogin", { fastify.post("/api/supplierlogin", {

Loading…
Cancel
Save