diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 4e36c00e..3c3f09e3 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -1,7 +1,7 @@ //Get the data models const { Supplier, DeliveryBoy } = require('../models/supplier'); const { FriendRequest } = require('../models/supplier') -const { ProfilePicture } = require('../models/User') +const { ProfilePicture, User } = require('../models/User') const supplierController = require("../controllers/supplierController"); const customJwtAuth = require("../customAuthJwt"); const fastify = require("fastify")({ @@ -854,3 +854,32 @@ exports.getPendingSuppliers = async (req, reply) => { }; + +exports.getPendingCustomers = 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: ["pending","rejected"] }); + 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); + } +}; + + diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index 03087b14..6953ba4f 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -81,6 +81,32 @@ module.exports = function (fastify, opts, next) { handler: validationHandler.getPendingSuppliers, }); + + + fastify.get("/api/pendingCustomers/:supplierId", { + schema: { + tags: ["Supplier-Data"], + description: "This is for Get All pending/rejected Customers", + summary: "This is for to Get All pending/rejected Customers", + params: { + type: "object", + properties: { + supplierId: { + type: "string", + description: "supplierId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + }, + handler: validationHandler.getPendingCustomers, + }); + fastify.post("/api/supplierlogin", {