From e3490c5424f901d0730ad77bb6b49b67ac40b9cb Mon Sep 17 00:00:00 2001 From: varun Date: Mon, 27 Mar 2023 03:39:39 -0400 Subject: [PATCH] once the connect request is sent it will not show in connection request --- src/handlers/supplierHandler.js | 28 +++++++++++++++++++++++++++- src/routes/supplierRoute.js | 12 +++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 569d1f0e..8615f467 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -1,5 +1,6 @@ //Get the data models const { Supplier } = require('../models/supplier'); +const { FriendRequest } = require('../models/supplier') const { ProfilePicture } = require('../models/User') const supplierController = require("../controllers/supplierController"); const customJwtAuth = require("../customAuthJwt"); @@ -537,7 +538,7 @@ exports.getCurrentSupplier = async (req, reply) => { } }; // Get all users -exports.getSuppliers = async (req, reply) => { +exports.getSuppliers1 = async (req, reply) => { const limit = parseInt(req.query.limit) || 100; const page = parseInt(req.query.page) || 1; const startindex = (page - 1) * limit; @@ -558,6 +559,31 @@ exports.getSuppliers = async (req, reply) => { } }; +exports.getSuppliers = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object + try { + const friendRequests = await FriendRequest.find({ customerId }); + const supplierIdsToExclude = friendRequests.map((request) => request.supplierId); + 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 }); + }); + } catch (err) { + throw boom.boomify(err); + } +}; + + // Get single user by ID exports.getSingleSupplier = async (req, reply) => { try { diff --git a/src/routes/supplierRoute.js b/src/routes/supplierRoute.js index 9f4f92ed..2a5cd4d6 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -7,11 +7,21 @@ const validationHandler = require("../handlers/supplierHandler"); module.exports = function (fastify, opts, next) { - fastify.get("/api/suppliers", { + fastify.get("/api/suppliers/:customerId", { schema: { tags: ["Supplier-Data"], description: "This is for Get All Suppliers", summary: "This is for to Get All Suppliers", + params: { + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + security: [ { basicAuth: [],