From d6b5a26de0da2f11f1f7f9b7fdaec8eff77ad719 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Tue, 4 Mar 2025 15:07:08 +0530 Subject: [PATCH] installer assigned by team member --- src/controllers/installationController.js | 67 +++++++++++++++++++++++ src/routes/installationRoute.js | 64 ++++++++++++---------- 2 files changed, 101 insertions(+), 30 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 988040fe..76d5f1b6 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -135,6 +135,73 @@ exports.createTeamMember = async (request, reply) => { } }; + exports.assignTeamMemberToQuotation = async (request, reply) => { + try { + const { installationId } = request.params; // Get installationId from URL params + const { teamMemberId } = request.body; // Get teamMemberId from request body + + if (!teamMemberId) { + return reply.status(400).send({ + simplydata: { + error: true, + message: "teamMemberId is required", + }, + }); + } + + // Find installation by installationId + const installation = await Install.findOne({ installationId }); + + if (!installation) { + return reply.status(404).send({ + simplydata: { + error: true, + message: "Installation not found", + }, + }); + } + + // Extract team members list + const teamMembers = installation.team_member.team_member; + + // Check if provided teamMemberId exists in the installation's team + const assignedTeamMember = teamMembers.find(member => member.teamMemberId === teamMemberId); + + if (!assignedTeamMember) { + return reply.status(404).send({ + simplydata: { + error: true, + message: "Team member not found in this installation", + }, + }); + } + + // Here, you would save the assigned team member to the quotation (modify as needed) + const quotation = { + installationId, + assignedTeamMember + }; + + return reply.send({ + simplydata: { + error: false, + message: "Team member assigned to quotation successfully", + quotation + }, + }); + + } catch (err) { + console.error("Error assigning team member to quotation:", err); + reply.status(500).send({ + simplydata: { + error: true, + message: "Internal server error", + }, + }); + } +}; + + exports.getAllInstallers = async (request, reply) => { try { const { departmentName } = request.params; // Get installationId from request params diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index caf10a6f..57e2a102 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -41,39 +41,41 @@ module.exports = function (fastify, opts, next) { }, required: ["installationId"] }, - response: { - 200: { - type: "object", - properties: { - simplydata: { - type: "object", - properties: { - error: { type: "boolean" }, - message: { type: "string" }, - teamMembers: { - type: "array", - items: { - type: "object", - properties: { - teamMemberId: { type: "string" }, - name: { type: "string" }, - phone: { type: "string" }, - email: { type: "string" }, - alternativePhone: { type: "string" }, - installationTeamMemId: { type: "string" }, - status: { type: "string" } - } - } - } - } - } - } - } - } + }, handler: installationController.getTeamMembers }); + fastify.post("/api/assignTeammember/:installationId", { + schema: { + description: "Assign a team member to an installation's quotation", + tags: ["Installation"], + summary: "Assign a team member based on installationId", + params: { + type: "object", + properties: { + installationId: { + type: "string", + description: "Installation ID to fetch team members from" + } + }, + required: ["installationId"] + }, + body: { + type: "object", + properties: { + teamMemberId: { + type: "string", + description: "The team member ID to assign" + } + }, + required: ["teamMemberId"] + }, + }, + handler: installationController.assignTeamMemberToQuotation + }); + + fastify.get("/api/getAllInstallers/:departmentName", { schema: { description: "Get All Installtion list", @@ -132,7 +134,9 @@ module.exports = function (fastify, opts, next) { } }, handler: installationController.editTeamMember - });fastify.delete("/api/deleteTeamMember/:installationId/:teamMemberId", { + }); + + fastify.delete("/api/deleteTeamMember/:installationId/:teamMemberId", { schema: { description: "Delete a team member from an installation", tags: ["Installation"],