pending and reject apis supplier and customer

master
Bhaskara Kishore 3 years ago
parent 18ac80e0a7
commit 0bcb16613f

@ -857,7 +857,35 @@ exports.getPendingSuppliers = async (req, reply) => {
const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object const customerId = req.params.customerId; // Assuming you have already authenticated the user and stored their ID in the request object
try { try {
const friendRequests = await FriendRequest.find({ customerId, status: ["pending","rejected"] }); const friendRequests = await FriendRequest.find({ customerId, status: ["pending"] });
// 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);
}
};
exports.getRejectSuppliers = 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: ["rejected"] });
// console.log(friendRequests,customerId) // console.log(friendRequests,customerId)
const supplierIdsToInclude = friendRequests.map((request) => request.supplierId); const supplierIdsToInclude = friendRequests.map((request) => request.supplierId);
// console.log(supplierIdsToInclude) // console.log(supplierIdsToInclude)
@ -879,6 +907,7 @@ exports.getPendingSuppliers = async (req, reply) => {
exports.getPendingCustomers = async (req, reply) => { exports.getPendingCustomers = async (req, reply) => {
const limit = parseInt(req.query.limit) || 100; const limit = parseInt(req.query.limit) || 100;
const page = parseInt(req.query.page) || 1; const page = parseInt(req.query.page) || 1;
@ -886,7 +915,7 @@ exports.getPendingCustomers = async (req, reply) => {
const supplierId = req.params.supplierId; // Assuming you have already authenticated the user and stored their ID in the request object const supplierId = req.params.supplierId; // Assuming you have already authenticated the user and stored their ID in the request object
try { try {
const friendRequests = await FriendRequest.find({ supplierId, status: ["pending","rejected"] }); const friendRequests = await FriendRequest.find({ supplierId, status: ["pending"] });
console.log(friendRequests,supplierId, "su....") console.log(friendRequests,supplierId, "su....")
const supplierIdsToInclude = friendRequests.map((request) => request.customerId); const supplierIdsToInclude = friendRequests.map((request) => request.customerId);
console.log(supplierIdsToInclude, "supplierIdsToInclude..") console.log(supplierIdsToInclude, "supplierIdsToInclude..")
@ -907,6 +936,33 @@ exports.getPendingCustomers = async (req, reply) => {
}; };
exports.getRejectCustomers = 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: ["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);
}
};
exports.getconnectedCustomers = async (req, reply) => { exports.getconnectedCustomers = async (req, reply) => {
const limit = parseInt(req.query.limit) || 100; const limit = parseInt(req.query.limit) || 100;

@ -60,8 +60,8 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/pendingSuppliers/:customerId", { fastify.get("/api/pendingSuppliers/:customerId", {
schema: { schema: {
tags: ["Supplier-Data"], tags: ["Supplier-Data"],
description: "This is for Get All pending/rejected Suppliers", description: "This is for Get All pending Suppliers",
summary: "This is for to Get All pending/rejected Suppliers", summary: "This is for to Get All pending Suppliers",
params: { params: {
type: "object", type: "object",
properties: { properties: {
@ -81,13 +81,62 @@ module.exports = function (fastify, opts, next) {
handler: validationHandler.getPendingSuppliers, handler: validationHandler.getPendingSuppliers,
}); });
fastify.get("/api/rejectSuppliers/:customerId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All rejected Suppliers",
summary: "This is for to Get All rejected Suppliers",
params: {
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getRejectSuppliers,
});
fastify.get("/api/rejectCustomers/:supplierId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All rejected Customers",
summary: "This is for to Get All rejected Customers",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getRejectCustomers,
});
fastify.get("/api/pendingCustomers/:supplierId", { fastify.get("/api/pendingCustomers/:supplierId", {
schema: { schema: {
tags: ["Supplier-Data"], tags: ["Supplier-Data"],
description: "This is for Get All pending/rejected Customers", description: "This is for Get All pending Customers",
summary: "This is for to Get All pending/rejected Customers", summary: "This is for to Get All pending Customers",
params: { params: {
type: "object", type: "object",
properties: { properties: {

Loading…
Cancel
Save