From 0f537efc1f5b78058dfdabcf15193caa9f69c710 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 20 Aug 2025 16:29:34 +0530 Subject: [PATCH] changes --- src/controllers/departmentController.js | 20 ++++++++++++++++++ src/routes/departmentRoute.js | 27 ++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index 9cb9afb7..872833f6 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -605,6 +605,26 @@ exports.addDepartment = async (request, reply) => { } }; + exports.getDetails = async (request, reply) => { + try { + const { id } = request.params; + let data; + + if (id.startsWith('AWBR')) { + data = await Branch.findOne({ branchId: id }); + } else { + data = await City.findOne({ cityId: id }); + } + + if (!data) { + return reply.status(404).send({ message: 'Not found' }); + } + + reply.send({ data }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; exports.getCityDetails = async (request, reply) => { try { const cityId = request.params.cityId; diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index 303cabcc..1794c16f 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -175,21 +175,38 @@ module.exports = function (fastify, opts, next) { }, handler: departmentController.editcity, }); +// fastify.route({ +// method: "GET", +// url: "/api/city/:cityId", +// schema: { +// tags: ["Department"], +// description: "This is for fetching a City details", +// summary: "This is for fetching a City details", +// params: { +// type: "object", +// properties: { +// cityId: { type: "string" } +// } +// } +// }, +// handler: departmentController.getCityDetails +// }); + fastify.route({ method: "GET", - url: "/api/city/:cityId", + url: "/api/details/:id", schema: { tags: ["Department"], - description: "This is for fetching a City details", - summary: "This is for fetching a City details", + description: "This is for fetching details of a branch or city", + summary: "This is for fetching details of a branch or city", params: { type: "object", properties: { - cityId: { type: "string" } + id: { type: "string" } } } }, - handler: departmentController.getCityDetails + handler: departmentController.getDetails }); fastify.route({ method: "GET",