diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 23d1ee52..87a0e381 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -557,9 +557,16 @@ exports.connectionStatus = async (req, reply) => { exports.connectstatus = async (req, reply) => { + + + + + + try { const customerId = req.params.customerId; const supplierId = req.query.supplierId; + console.log(req.params.customerId) console.log(req.query.supplierId) const data = await FriendRequest.findOne({ customerId: customerId, supplierId: supplierId }); diff --git a/src/handlers/supplierHandler.js b/src/handlers/supplierHandler.js index 568d6e1f..18dced6c 100644 --- a/src/handlers/supplierHandler.js +++ b/src/handlers/supplierHandler.js @@ -600,10 +600,9 @@ exports.getConnectedSuppliers = async (req, reply) => { 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 - console.log(customerId,"HI") try { const friendRequests = await FriendRequest.find({ customerId, status: "accepted" }); - console.log(friendRequests,customerId) + // console.log(friendRequests,customerId) const supplierIdsToInclude = friendRequests.map((request) => request.supplierId); await Supplier.find({ supplierId: { $in: supplierIdsToInclude } }) .limit(limit) @@ -622,3 +621,32 @@ exports.getConnectedSuppliers = async (req, reply) => { }; + +exports.getPendingSuppliers = 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, status: ["pending","rejected"] }); + // console.log(friendRequests,customerId) + const supplierIdsToInclude = friendRequests.map((request) => request.supplierId); + // console.log(supplierIdsToInclude) + await Supplier.find({ supplierId: { $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 986fff0c..ee33a76b 100644 --- a/src/routes/supplierRoute.js +++ b/src/routes/supplierRoute.js @@ -56,6 +56,31 @@ module.exports = function (fastify, opts, next) { handler: validationHandler.getConnectedSuppliers, }); + + fastify.get("/api/pendingSuppliers/:customerId", { + schema: { + tags: ["Supplier-Data"], + description: "This is for Get All pending/rejected Suppliers", + summary: "This is for to Get All pending/rejected Suppliers", + params: { + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + }, + handler: validationHandler.getPendingSuppliers, + }); + fastify.post("/api/supplierlogin", {