const fastify = require("fastify"); const adminController = require('../controllers/admincontroller') module.exports = function (fastify, opts, next) { fastify.route({ method: "POST", url: "/api/adminSignup", schema: { tags: ["Admin"], description: "This is for creating a new Admin/sales/store Account", summary: "This is for creating a new Admin/sales/store Account", body: { type: "object", required: ["phone", "username", "password", "role"], // Add role to required fields properties: { phone: { type: "string" }, password: { type: "string" }, username: { type: "string" }, role: { type: "string", enum: ["admin", "sales", "store"] }, // Define allowed roles }, }, security: [ { basicAuth: [], }, ], }, handler: adminController.adminSignUp, }); fastify.put('/api/editAdmin/:customerId', { schema: { description: "Edit Admin details by CustomerId", tags: ["Admin"], summary: "Edit Admin details by CustomerId", params: { type: "object", properties: { customerId: { type: "string" }, }, required: ["customerId"], }, body: { type: "object", properties: { phone: { type: "string" }, username: { type: "string" }, picture: { type: "string" }, }, } }, handler: adminController.editAdmin, }); fastify.post("/api/adminLogin", { schema: { description: "This is for Login Admin", tags: ["Admin"], summary: "This is for Login Admin", body: { type: "object", required: ["phone", "password"], properties: { phone : { type: "string" }, password: { type: "string" }, }, }, }, handler: adminController.adminLogin, }); fastify.post("/api/salesStoreLogin", { schema: { description: "Login for sales/store users", tags: ["Sales/Store Login"], summary: "Login for sales/store users", body: { type: "object", required: ["phone", "password", "role"], properties: { phone : { type: "string" }, password: { type: "string" }, role: { type: "string", enum: ["sales", "store"] } }, }, }, handler: adminController.salesStoreLogin, }); fastify.get("/api/getUsersByRole/:role", { schema: { description: "Get list of users by role (sales/store)", tags: ["Sales/Store Users"], summary: "Get list of users by role", params: { type: "object", properties: { role: { type: "string", enum: ["sales", "store"] }, }, required: ["role"], }, response: { 200: { type: "array", items: { type: "object", properties: { phone: { type: "string" }, username: { type: "string" }, role: { type: "string" }, date: { type: "string", format: "date-time" } } } } } }, handler: adminController.getUsersByRole, }); fastify.put("/api/editUser/:customerId", { schema: { description: "Edit user details by customer ID", tags: ["Sales/Store Users"], summary: "Edit user details", params: { type: "object", properties: { customerId: { type: "string" }, // Customer ID }, required: ["customerId"], }, body: { type: "object", properties: { phone: { type: "string" }, username: { type: "string" }, role: { type: "string", enum: ["sales", "store"] }, date: { type: "string", format: "date-time" } }, required: ["phone", "username", "role", "date"] }, response: { 200: { type: "object", properties: { success: { type: "boolean" }, message: { type: "string" }, } } } }, handler: adminController.editUserByCustomerId, }); fastify.delete("/api/deleteUser/:customerId", { schema: { description: "Delete a user by customer ID", tags: ["Sales/Store Users"], summary: "Delete a user by customer ID", params: { type: "object", properties: { customerId: { type: "string" }, // Customer ID }, required: ["customerId"], }, response: { 200: { type: "object", properties: { success: { type: "boolean" }, message: { type: "string" }, } } } }, handler: adminController.deleteUserInfo, }); fastify.route({ method: "GET", url: "/api/users/:customerId", // Use path parameters for customerId schema: { tags: ["Admin"], description: "Retrieve user information by customerId", summary: "Get user by customerId", params: { type: "object", required: ["customerId"], properties: { customerId: { type: "string" }, }, }, security: [ { basicAuth: [], }, ], }, handler: adminController.getUserByCustomerId, // Link the handler function }); // fastify.post("/api/createUser", { // schema: { // description: "This is for Create sale/store", // tags: ["createUser for sale/sore"], // summary: "This is for Create sale/store", // body: { // type: "object", // required: ["phone", "password", "role"], // properties: { // phone : { type: "string" }, // password: { type: "string" }, // role: { type: "string", enum: ["sales", "store"] } // }, // }, // }, // handler: adminController.createUser, // }); fastify.post("/api/integratingHardwareidToTank", { schema: { description: "This is for integrating hardwareId with tank", tags: ["Admin"], summary: "This is for integrating hardwareId with tank", body: { type: "object", properties: { hardwareId_company:{ type: "string" }, hardwareId_type:{ type: "string" }, customerId: { type: "string" }, tankName: { type: "string" }, tankLocation: { type: "string" }, hardwareId: { type: "string" }, }, }, }, handler: adminController.integratingHardwareidToTank, }); fastify.post("/api/getDepartmentDetails/:adminId", { schema: { description: "Get department details by adminId, departmentName and reportingManager", tags: ["Admin"], summary: "Get department details", params: { type: "object", properties: { adminId: { type: "string", description: "Admin ID" } }, required: ["adminId"] }, body: { type: "object", properties: { departmentName: { type: "string" }, reportingManager: { type: "string" } }, required: ["departmentName", "reportingManager"] } }, handler: adminController.getDepartmentDetailsByAdminAndName }); fastify.get("/api/getAllCompanies", { schema: { tags: ["Admin"], description: "Get all Companies List", summary: "Get all Companies List", }, handler: adminController.getAllCompanys, }); fastify.get("/api/getBranchDetails", { schema: { tags: ["Admin"], description: "Get Branch Details", summary: "Get Branch Details", // params: { // type: "object", // properties: { // officeName: { type: "string", description: "Office name" } // }, // required: ["officeName"] // }, querystring: { // ✅ allow customerId in query string type: 'object', required: ['officeName'], properties: { officeName: { type: 'string' } } } }, handler: adminController.getAllOffices, }); fastify.get("/api/getOfficesByCity", { schema: { tags: ["Admin"], description: "Get Offices by City", summary: "Fetch Head Offices and Branches by City", querystring: { type: 'object', required: ['city'], properties: { city: { type: 'string' } } } }, handler: adminController.getAllOfficesByCity, }); fastify.put("/api/editTeamMember/:departmentId/:teamMemberId", { schema: { description: "Admin Edit Team Member", tags: ["Admin"], summary: "Admin Edit Team Member", params: { type: "object", properties: { departmentId: { type: "string", description: "departmentId" }, teamMemberId: { type: "string", description: "Team Member ID" } }, required: ["departmentId", "teamMemberId"] }, body: { type: "object", properties: { firstName: { type: "string" }, phone: { type: "string" }, email: { type: "string" }, alternativePhone: { type: "string" }, } }, }, handler: adminController.adminEditTeamMember }); fastify.delete("/api/admin/admindeleteTeamMember/:departmentId/:teamMemberId", { schema: { description: "Delete a team member from an Admin", tags: ["Admin"], summary: "Admin Delete Team Member", params: { type: "object", properties: { departmentId: { type: "string", description: "departmentId" }, teamMemberId: { type: "string", description: "Team Member ID" } }, required: ["departmentId", "teamMemberId"] }, response: { 200: { type: "object", properties: { simplydata: { type: "object", properties: { error: { type: "boolean" }, message: { type: "string" } } } } } } }, handler: adminController.AdmindeleteTeamMember }); fastify.get("/api/getOfficeDetails/:officeName/:city", { schema: { tags: ["Admin"], description: "Get office details from both City and Branch collections", summary: "Get merged office data", params: { type: "object", properties: { officeName: { type: "string" }, city: { type: "string" } }, required: ["officeName", "city"] }, }, handler: adminController.getOfficeDetails }); next(); };