get all pending customer from friend-request

master
Bhaskara Kishore 3 years ago
parent 06342b492f
commit dda1cc78de

@ -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);
}
};

@ -83,6 +83,32 @@ module.exports = function (fastify, opts, next) {
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", {
schema: {
description: "This is for Login Supplier",

Loading…
Cancel
Save