diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 24ffcb87..6e6e79ec 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -1645,6 +1645,38 @@ exports.getuserRequestbookingsforplansforsupplier = async (req, reply) => { } }; +exports.getuserRequestbookingsforplansforcustomer = async (req, reply) => { + try { + const { customerId } = req.params; + + if (!customerId) { + return reply.code(400).send({ + status_code: 400, + message: "customerId is required", + }); + } + + // 1) Find all bookings that include this supplier + const bookings = await RecurringRequestedBooking.find({ + customerId: customerId, + }) + .sort({ createdAt: -1 }) + .lean(); + + // 2) For each booking, expose only this supplier's subdocument + + + + return reply.send({ + status_code: 200, + message: `Orders for customer ${customerId} fetched successfully`, + data:bookings, + }); + } catch (err) { + console.error(err); + throw boom.boomify(err); + } +}; const mongoose = require('mongoose'); diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 736bdd16..1f67cf6b 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -1221,6 +1221,27 @@ fastify.route({ }); +fastify.route({ + method: "GET", + url: "/api/getuserRequestbookingsforplansforcustomer/:customerId", + schema: { + description: "Fetch plans of the customer", + tags: ["Supplier"], + summary: "Fetch plans of the customer", + params: { + type: "object", + properties: { + customerId: { type: "string", description: "customerId" }, + }, + required: ["customerId"], + }, + security: [{ basicAuth: [] }], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: userController.getuserRequestbookingsforplansforcustomer, +}); + + fastify.route({ method: "POST",