From 78bfa5afcc3f9a88eb971301d912b0dbf3aaa9fa Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Wed, 29 Mar 2023 11:36:28 +0530 Subject: [PATCH] connected customers --- src/handlers/supplierHandler.js | 27 +++++++++++++++++++++++++++ src/routes/supplierRoute.js | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 3c3f09e3..7cae812b 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -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); + } +}; \ No newline at end of file diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index 6953ba4f..09b026ec 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -107,6 +107,31 @@ module.exports = function (fastify, opts, next) { 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", {