Bhaskara Kishore 3 years ago
commit b318765013

@ -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");
@ -536,13 +537,37 @@ exports.getCurrentSupplier = async (req, reply) => {
throw boom.boomify(err);
}
};
// Get all users
// Get all suppliers
// exports.getSuppliers = async (req, reply) => {
// const limit = parseInt(req.query.limit) || 100;
// const page = parseInt(req.query.page) || 1;
// const startindex = (page - 1) * limit;
// try {
// await Supplier.find()
// .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.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 {
await Supplier.find()
const friendRequests = await FriendRequest.find({ customerId });
const supplierIdsToExclude = friendRequests.map((request) => request.supplierId);
await Supplier.find({ supplierId: { $nin: supplierIdsToExclude } })
.limit(limit)
.skip(startindex)
.exec()
@ -558,6 +583,7 @@ exports.getSuppliers = async (req, reply) => {
}
};
// Get single user by ID
exports.getSingleSupplier = async (req, reply) => {
try {
@ -568,3 +594,31 @@ exports.getSingleSupplier = async (req, reply) => {
throw boom.boomify(err);
}
};
exports.getConnectedSuppliers = 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
console.log(customerId,"HI")
try {
const friendRequests = await FriendRequest.find({ customerId, status: "accepted" });
console.log(friendRequests,customerId)
const supplierIdsToInclude = friendRequests.map((request) => request.supplierId);
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);
}
};

@ -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: [],
@ -21,6 +31,33 @@ module.exports = function (fastify, opts, next) {
handler: validationHandler.getSuppliers,
});
fastify.get("/api/connectedSuppliers/:customerId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All connected Suppliers",
summary: "This is for to Get All connected Suppliers",
params: {
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getConnectedSuppliers,
});
fastify.post("/api/supplierlogin", {
schema: {
description: "This is for Login Supplier",

Loading…
Cancel
Save