diff --git a/src/controllers/admincontroller.js b/src/controllers/admincontroller.js index 5775accc..d0125289 100644 --- a/src/controllers/admincontroller.js +++ b/src/controllers/admincontroller.js @@ -59,16 +59,6 @@ exports.adminSignUp = async (request, reply) => { - // Check if an admin with the same phone number or username already exists - // const existingAdminUsername = await Admin.findOne({ username }); - // const existingAdmin = await Admin.findOne({ phone }); - - // if (existingAdmin) { - // return reply.status(400).send({ message: 'Phone already registered' }); - // } - // if (existingAdminUsername) { - // return reply.status(400).send({ message: 'Username already registered' }); - // } // Hash the password using bcrypt const hashedPassword = await bcrypt.hash(password, 10); @@ -122,34 +112,6 @@ exports.editAdmin = async (request, reply) => { }; -// Admin Login Function (With Phone Number) -// exports.adminLogin = async (request, reply) => { -// try { -// const { phone, password } = request.body; - -// // Check if an admin with the phone number exists -// const admin = await Admin.findOne({ phone }); - -// if (!admin) { -// return reply.status(401).send({ message: 'Invalid phone number or password' }); -// } - -// // Compare the password entered by the user with the hashed password stored in the database -// const isPasswordValid = await bcrypt.compare(password, admin.password); - -// if (!isPasswordValid) { -// return reply.status(401).send({ message: 'Invalid phone number or password' }); -// } - - -// // Generate a JWT token for the authenticated admin -// const token = jwt.sign({ phone: admin.phone, role: 'admin' }, JWT_SECRET, { expiresIn: '1h' }); - -// return reply.send({ token, admin }); -// } catch (err) { -// reply.status(500).send({ message: err.message }); -// } -// }; exports.adminLogin = async (request, reply) => { try { @@ -440,276 +402,10 @@ exports.getAllCompanys = async (req, reply) => { } }; -// exports.getBranchDetails = async (req, reply) => { -// try { -// const { officeName } = req.params; - -// const branchDetails = await Branch.find({ -// officeName: { $regex: new RegExp(`^${officeName}$`, 'i') } -// }); - -// return reply.send({ -// status_code: 200, -// message: "Fetched successfully", -// data: branchDetails, -// }); -// } catch (err) { -// console.error("Error fetching branch details:", err); -// return reply.status(500).send({ error: "Internal server error" }); -// } -// }; - - -// exports.getAllOffices = async (req, reply) => { -// try { -// const { officeName } = req.query; - -// let filter = {}; - -// if (officeName && officeName.toUpperCase() !== "ALL") { -// // Partial and case-insensitive match -// filter.officeName = { $regex: new RegExp(officeName, "i") }; -// } - -// const offices = await Branch.find(filter).lean(); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: offices -// }); -// } catch (error) { -// console.error("Error fetching offices:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error" -// }); -// } -// }; - -// exports.getAllOffices = async (req, reply) => { -// try { -// const { officeName } = req.query; - -// if (!officeName) { -// return reply.code(400).send({ -// status_code: 400, -// message: "officeName query param is required" -// }); -// } - -// const nameRegex = new RegExp(officeName.trim(), "i"); - -// // Fetch head offices, branches, and departments -// const [headOffices, branches, departments] = await Promise.all([ -// City.find({ officeName: nameRegex }).lean(), -// Branch.find({ officeName: nameRegex }).lean(), -// Deparments.find({ officeName: nameRegex }).lean() -// ]); - -// if (headOffices.length === 0 && branches.length === 0) { -// return reply.code(404).send({ -// status_code: 404, -// message: "No offices found for the given officeName" -// }); -// } - -// const allOffices = []; - -// // Process head offices (with employee count) -// headOffices.forEach(ho => { -// const officeNameTrimmed = ho.officeName.trim().toLowerCase(); - -// // Get all department docs for this office -// const matchingDepartments = departments.filter( -// d => d.officeName?.trim().toLowerCase() === officeNameTrimmed -// ); - -// // Count employees: 1 main person per doc + sub-team members -// const employeeCount = matchingDepartments.reduce((count, dep) => { -// const mainPerson = 1; -// const subTeamCount = Array.isArray(dep?.team_member?.team_member) -// ? dep.team_member.team_member.length -// : 0; -// return count + mainPerson + subTeamCount; -// }, 0); - -// allOffices.push({ -// officeType: "headOffice", -// officeName: ho.officeName.trim(), -// city: ho.city?.trim() || "", -// cityId: ho.cityId || "", -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "", -// latitude:ho.latitude || "", -// longitude: ho.longitude || "", -// googleLocation: ho.googleLocation || "", -// createdAt: ho.createdAt || "", -// updatedAt: ho.updatedAt || "" -// }); -// }); - -// // Process branches (no employee count here) -// branches.forEach(br => { -// allOffices.push({ -// officeType: "branch", -// branchId: br.branchId || "", -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// zone: br.zone || "", -// location: br.location || [], -// phone: br.phone || "", -// address: br.office_address1 || "", -// address2: br.address2 || "", -// state: br.state || "", -// country: br.country || "", -// pincode: br.pincode || "", -// email: br.email || "", -// contactPerson: br.nameoftheContactPerson || "", -// latitude:br.latitude || "", -// longitude: br.longitude || "", -// googleLocation: br.googleLocation || "", -// createdAt: br.createdAt || "", -// updatedAt: br.updatedAt || "" -// }); -// }); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: allOffices -// }); - -// } catch (error) { -// console.error("Error fetching city offices:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error" -// }); -// } -// }; - - -// exports.getAllOffices = async (req, reply) => { -// try { -// const { officeName } = req.query; - -// if (!officeName) { -// return reply.code(400).send({ -// status_code: 400, -// message: "officeName query param is required" -// }); -// } - -// let headOffices, branches, departments; - -// if (officeName.trim().toUpperCase() === "ALL") { -// // ✅ Fetch all without filtering -// [headOffices, branches, departments] = await Promise.all([ -// City.find().lean(), -// Branch.find().lean(), -// Deparments.find().lean() -// ]); -// } else { -// const nameRegex = new RegExp(officeName.trim(), "i"); -// [headOffices, branches, departments] = await Promise.all([ -// City.find({ officeName: nameRegex }).lean(), -// Branch.find({ officeName: nameRegex }).lean(), -// Deparments.find({ officeName: nameRegex }).lean() -// ]); -// } - -// if (headOffices.length === 0 && branches.length === 0) { -// return reply.code(404).send({ -// status_code: 404, -// message: "No offices found" -// }); -// } - -// const allOffices = []; - -// // Process head offices (with employee count) -// headOffices.forEach(ho => { -// const officeNameTrimmed = ho.officeName.trim().toLowerCase(); - -// // Get all department docs for this office -// const matchingDepartments = departments.filter( -// d => d.officeName?.trim().toLowerCase() === officeNameTrimmed -// ); - -// // Count employees: 1 main person per doc + sub-team members -// const employeeCount = matchingDepartments.reduce((count, dep) => { -// const mainPerson = 1; -// const subTeamCount = Array.isArray(dep?.team_member?.team_member) -// ? dep.team_member.team_member.length -// : 0; -// return count + mainPerson + subTeamCount; -// }, 0); - -// allOffices.push({ -// officeType: "headOffice", -// officeName: ho.officeName.trim(), -// city: ho.city?.trim() || "", -// cityId: ho.cityId || "", -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "", -// latitude: ho.latitude || "", -// longitude: ho.longitude || "", -// googleLocation: ho.googleLocation || "", -// createdAt: ho.createdAt || "", -// updatedAt: ho.updatedAt || "" -// }); -// }); - -// // Process branches (no employee count here) -// branches.forEach(br => { -// allOffices.push({ -// officeType: "branch", -// branchId: br.branchId || "", -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// zone: br.zone || "", -// location: br.location || [], -// phone: br.phone || "", -// address: br.office_address1 || "", -// address2: br.address2 || "", -// state: br.state || "", -// country: br.country || "", -// pincode: br.pincode || "", -// email: br.email || "", -// contactPerson: br.nameoftheContactPerson || "", -// latitude: br.latitude || "", -// longitude: br.longitude || "", -// googleLocation: br.googleLocation || "", -// createdAt: br.createdAt || "", -// updatedAt: br.updatedAt || "" -// }); -// }); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: allOffices -// }); - -// } catch (error) { -// console.error("Error fetching city offices:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error" -// }); -// } -// }; + + + + exports.getAllOffices = async (req, reply) => { try { @@ -981,555 +677,6 @@ exports.getAllOfficesByCity = async (req, reply) => { -// exports.getAllOfficesByCity = async (req, reply) => { -// try { -// const { city } = req.query; - -// if (!city) { -// return reply.code(400).send({ -// status_code: 400, -// message: "city query param is required" -// }); -// } - -// const cityRegex = new RegExp(city.trim(), "i"); - -// // 1) Find head offices (city schema) -// const headOffices = await City.find({ city: cityRegex }).lean(); - -// if (!headOffices.length) { -// return reply.code(404).send({ -// status_code: 404, -// message: `No head office found for city ${city}` -// }); -// } - -// // 2) Build response for each headOffice -// const finalResponse = []; - -// for (const ho of headOffices) { -// // (optional) Employee count logic -// const departments = await Deparments.find({ city: ho.city }).lean(); -// const employeeCount = departments.reduce((count, dep) => { -// const mainPerson = 1; -// const subTeamCount = Array.isArray(dep?.team_member?.team_member) -// ? dep.team_member.team_member.length -// : 0; -// return count + mainPerson + subTeamCount; -// }, 0); - -// // 3) Find branches with same officeName -// const branches = await Branch.find({ -// officeName: new RegExp(ho.officeName.trim(), "i") -// }).lean(); - -// // 4) Construct office data -// const offices = []; - -// // Head Office (from citySchema) -// offices.push({ -// officeType: "headOffice", -// officeName: ho.officeName?.trim() || "", -// city: ho.city?.trim() || "", -// cityId: ho.cityId || "", -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// address2: ho.address2 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "", -// latitude: ho.latitude || 0, -// longitude: ho.longitude || 0, -// googleLocation: ho.googleLocation || "", -// createdAt: ho.createdAt || "", -// updatedAt: ho.updatedAt || "" -// }); - -// // Branches (from branchSchema) -// branches.forEach(br => { -// offices.push({ -// officeType: "branchOffice", -// branchId: br.branchId || "", -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// employeeCount, // optional: same count or separate -// phone: br.phone || "", -// address: br.office_address1 || "", -// address2: br.address2 || "", -// state: br.state || "", -// country: br.country || "", -// pincode: br.pincode || "", -// email: br.email || "", -// contactPerson: br.nameoftheContactPerson || "", -// latitude: br.latitude || 0, -// longitude: br.longitude || 0, -// googleLocation: br.googleLocation || "", -// createdAt: br.createdAt || "", -// updatedAt: br.updatedAt || "" -// }); -// }); - -// // 5) Push into final response -// finalResponse.push({ -// officeName: ho.officeName?.trim() || "", -// city: ho.city?.trim() || "", -// offices -// }); -// } - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: finalResponse -// }); - -// } catch (error) { -// console.error("❌ Error in getAllOfficesByCity:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error", -// error: error.message -// }); -// } -// }; - - -// exports.getAllOfficesByCity = async (req, reply) => { -// try { -// const { city } = req.query; - -// if (!city) { -// return reply.code(400).send({ -// status_code: 400, -// message: "city query param is required" -// }); -// } - -// const cityRegex = new RegExp(city.trim(), "i"); - -// // Fetch head offices, branches, and departments -// const [headOffices, branches, departments] = await Promise.all([ -// City.find({ city: cityRegex }).lean(), -// Branch.find({ city: cityRegex }).lean(), -// Deparments.find({ city: cityRegex }).lean() -// ]); - -// if (!headOffices.length && !branches.length) { -// return reply.code(404).send({ -// status_code: 404, -// message: `No offices found in city ${city}` -// }); -// } - -// const officeMap = new Map(); - -// // 🔹 Process Head Offices -// headOffices.forEach(ho => { -// const cityTrimmed = ho.city?.trim().toLowerCase(); -// const matchingDepartments = departments.filter( -// d => d.city?.trim().toLowerCase() === cityTrimmed -// ); - -// // Count employees -// const employeeCount = matchingDepartments.reduce((count, dep) => { -// const mainPerson = 1; -// const subTeamCount = Array.isArray(dep?.team_member?.team_member) -// ? dep.team_member.team_member.length -// : 0; -// return count + mainPerson + subTeamCount; -// }, 0); - -// const officeNameKey = ho.officeName?.trim().toLowerCase(); - -// if (!officeMap.has(officeNameKey)) { -// officeMap.set(officeNameKey, { -// officeName: ho.officeName?.trim() || "", -// city: ho.city?.trim() || "", -// offices: [] -// }); -// } - -// officeMap.get(officeNameKey).offices.push({ -// officeType: "headOffice", -// officeName: ho.officeName?.trim() || "", -// city: ho.city?.trim() || "", -// cityId: ho.cityId || "", -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "", -// latitude: ho.latitude || "", -// longitude: ho.longitude || "", -// googleLocation: ho.googleLocation || "", -// createdAt: ho.createdAt || "", -// updatedAt: ho.updatedAt || "" -// }); -// }); - -// // 🔹 Process Branches -// branches.forEach(br => { -// const officeNameKey = br.officeName?.trim().toLowerCase(); - -// if (!officeMap.has(officeNameKey)) { -// officeMap.set(officeNameKey, { -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// offices: [] -// }); -// } - -// officeMap.get(officeNameKey).offices.push({ -// officeType: "branch", -// branchId: br.branchId || "", -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// zone: br.zone || "", -// location: Array.isArray(br.location) ? br.location : [], -// phone: br.phone || "", -// address: br.office_address1 || "", -// address2: br.address2 || "", -// state: br.state || "", -// country: br.country || "", -// pincode: br.pincode || "", -// email: br.email || "", -// contactPerson: br.nameoftheContactPerson || "", -// latitude: br.latitude || "", -// longitude: br.longitude || "", -// googleLocation: br.googleLocation || "", -// createdAt: br.createdAt || "", -// updatedAt: br.updatedAt || "" -// }); -// }); - -// // 🔹 Final grouped response -// const finalResponse = Array.from(officeMap.values()); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: finalResponse -// }); - -// } catch (error) { -// console.error("❌ Error in getAllOfficesByCity:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error", -// error: error.message -// }); -// } -// }; - - - - -// exports.getAllOfficesByCity = async (req, reply) => { -// try { -// const { city } = req.query; - -// if (!city) { -// return reply.code(400).send({ -// status_code: 400, -// message: "city query param is required" -// }); -// } - -// const cityRegex = new RegExp(city.trim(), "i"); - -// // Fetch head offices and branches in this city -// const headOffices = await City.find({ city: cityRegex }).lean(); -// const branches = await Branch.find({ city: cityRegex }).lean(); - -// if (!headOffices.length && !branches.length) { -// return reply.code(404).send({ -// status_code: 404, -// message: `No offices found in city ${city}` -// }); -// } - -// // Group by officeName -// const officeMap = new Map(); - -// // Process head offices -// headOffices.forEach(ho => { -// const key = ho.officeName?.trim().toLowerCase(); -// if (!officeMap.has(key)) { -// officeMap.set(key, { -// officeName: ho.officeName?.trim() || "", -// city: ho.city?.trim() || "", -// headOffices: [] -// }); -// } -// officeMap.get(key).headOffices.push({ -// officeType: "headOffice", -// city: ho.city?.trim() || "", -// employeeCount: ho.employeeCount || 0, -// phone: ho.phone || "", -// address: ho.address || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "" -// }); -// }); - -// // Process branches -// branches.forEach(br => { -// const key = br.officeName?.trim().toLowerCase(); -// if (!officeMap.has(key)) { -// officeMap.set(key, { -// officeName: br.officeName?.trim() || "", -// city: br.city?.trim() || "", -// headOffices: [] -// }); -// } -// officeMap.get(key).headOffices.push({ -// officeType: "branch", -// branchId: br.branchId || "", -// city: br.city?.trim() || "", -// zone: br.zone || "", -// phone: br.phone || "", -// address: br.address || "", -// state: br.state || "" -// }); -// }); - -// // Final response array -// const finalResponse = Array.from(officeMap.values()); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: finalResponse -// }); - -// } catch (err) { -// console.error("❌ Error in getAllOfficesByCity:", err); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error", -// error: err.message -// }); -// } -// }; - - - - - -// exports.getCityOffices = async (req, reply) => { -// try { -// const { officeName } = req.query; - -// if (!officeName) { -// return reply.code(400).send({ -// status_code: 400, -// message: "officeName query param is required" -// }); -// } - -// // Regex filter for partial & case-insensitive match -// const nameRegex = new RegExp(officeName.trim(), "i"); - -// // Step 1: Fetch head offices matching the officeName -// const headOffices = await City.find({ officeName: nameRegex }).lean(); - -// // Step 2: Fetch branches matching the officeName -// const branches = await Branch.find({ officeName: nameRegex }).lean(); - -// // Step 3: Fetch departments matching the officeName -// const departments = await Deparments.find({ officeName: nameRegex }).lean(); - -// if (headOffices.length === 0 && branches.length === 0) { -// return reply.code(404).send({ -// status_code: 404, -// message: "No offices found for the given officeName" -// }); -// } - -// // Step 4: Build city-wise result -// const cityMap = {}; - -// headOffices.forEach(ho => { -// const officeNameTrimmed = ho.officeName.trim(); - -// // Find department for this office to get employee count -// const departmentDoc = departments.find( -// d => -// d.officeName && -// d.officeName.trim().toLowerCase() === officeNameTrimmed.toLowerCase() -// ); -// const employeeCount = -// departmentDoc?.team_member?.team_member?.length || 0; - -// cityMap[ho.city.trim().toLowerCase()] = { -// city: ho.city.trim(), -// headOffice: { -// officeName: ho.officeName.trim(), -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "" -// }, -// branches: [] -// }; -// }); - -// // Step 5: Attach branches -// branches.forEach(br => { -// const cityKey = br.city.trim().toLowerCase(); -// if (!cityMap[cityKey]) { -// cityMap[cityKey] = { -// city: br.city.trim(), -// headOffice: null, -// branches: [] -// }; -// } -// cityMap[cityKey].branches.push({ -// officeName: br.officeName?.trim() || "", -// location: br.location || [], -// phone: br.phone || "", -// address: br.address1 || "" -// }); -// }); - -// // Step 6: Convert to array -// const result = Object.values(cityMap); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: result -// }); -// } catch (error) { -// console.error("Error fetching city offices:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error" -// }); -// } -// }; - -// exports.getCityOffices = async (req, reply) => { -// try { -// const { officeName } = req.query; - -// if (!officeName) { -// return reply.code(400).send({ -// status_code: 400, -// message: "officeName query param is required" -// }); -// } - -// const nameRegex = new RegExp(officeName.trim(), "i"); - -// // Step 1: Fetch head offices -// const headOffices = await City.find({ officeName: nameRegex }).lean(); - -// // Step 2: Fetch branches -// const branches = await Branch.find({ officeName: nameRegex }).lean(); - -// // Step 3: Fetch departments -// const departments = await Deparments.find({ officeName: nameRegex }).lean(); - -// if (headOffices.length === 0 && branches.length === 0) { -// return reply.code(404).send({ -// status_code: 404, -// message: "No offices found for the given officeName" -// }); -// } - -// const cityMap = {}; - -// headOffices.forEach(ho => { -// const officeNameTrimmed = ho.officeName.trim(); - -// // Find department for this office to get employee count -// const departmentDoc = departments.find( -// d => d.officeName?.trim().toLowerCase() === officeNameTrimmed.toLowerCase() -// ); -// console.log("departmentDoc",departmentDoc) -// const mainPersonCount = departmentDoc?.team_member?.main_person ? 1 : 0; -// const subTeamCount = Array.isArray(departmentDoc?.team_member?.team_member) -// ? departmentDoc.team_member.team_member.length -// : 0; - -// const employeeCount = mainPersonCount + subTeamCount; - -// cityMap[ho.city.trim().toLowerCase()] = { -// // cityId: ho.cityId || "", // added cityId -// city: ho.city.trim(), -// headOffice: { -// officeName: ho.officeName.trim(), -// cityId: ho.cityId || "", // added cityId -// employeeCount, -// phone: ho.phone || "", -// address: ho.office_address1 || "", -// state: ho.state || "", -// country: ho.country || "", -// pincode: ho.pincode || "", -// email: ho.email || "" -// }, -// // branches: [] -// }; -// }); - -// // Step 5: Attach branches -// branches.forEach(br => { -// const cityKey = br.city.trim().toLowerCase(); - -// if (!cityMap[cityKey]) { -// cityMap[cityKey] = { -// //cityId: br.cityId || "", -// city: br.city.trim(), -// // headOffice: null, -// branches: [] -// }; -// } - -// cityMap[cityKey].branches.push({ -// branchId: br.branchId || "", -// officeName: br.officeName?.trim() || "", -// zone: br.zone || "", -// location: br.location || [], -// phone: br.phone || "", -// address: br.office_address1 || "", -// address2: br.address2 || "", -// state: br.state || "", -// country: br.country || "", -// pincode: br.pincode || "", -// email: br.email || "", -// contactPerson: br.nameoftheContactPerson || "", -// createdAt: br.createdAt || "", -// updatedAt: br.updatedAt || "" -// }); -// }); - -// const result = Object.values(cityMap); - -// return reply.code(200).send({ -// status_code: 200, -// message: "Fetched successfully", -// data: result -// }); - -// } catch (error) { -// console.error("Error fetching city offices:", error); -// return reply.code(500).send({ -// status_code: 500, -// message: "Internal server error" -// }); -// } -// }; - exports.getCityOffices = async (req, reply) => { try { const { officeName } = req.query; diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index aaa00515..46a0376f 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -13,14 +13,6 @@ const fastify = require("fastify")({ const { Counter} = require('../models/User') const {Department, Desgination, City, Deparments, Branch, Zone,IndianLocations} = require('../models/Department') -// const generateDepartmentId = async (prefix) => { -// const result = await Counter.findOneAndUpdate( -// { _id: 'department_id' }, -// { $inc: { seq: 1 } }, -// { upsert: true, new: true } -// ); -// return `AW${prefix}${result.seq}`; -// }; const generateCityId = async () => { var result = await Counter.findOneAndUpdate( @@ -40,14 +32,6 @@ const generateCityId = async () => { return result.seq; }; -// const generateDesginationId = async (prefix) => { -// const result = await Counter.findOneAndUpdate( -// { _id: 'desgination_id' }, -// { $inc: { seq: 1 } }, -// { upsert: true, new: true } -// ); -// return `AW${prefix}${result.seq}`; -// }; const generateDepartmentId = async (city, departmentName) => { const cityPrefix = city.substring(0, 2).toUpperCase(); // Extract first two letters of city @@ -245,34 +229,7 @@ const generateDepartmentId = async (city, departmentName) => { reply.status(500).send({ message: err.message }); } }; -// exports.getSinledepartmentData = async (req, reply) => { -// try { -// const { departmentId } = req.params; - -// const department = await Department.findOne({ departmentId: departmentId }); - -// if (!department) { -// return reply.code(404).send({ -// success: false, -// message: 'Department not found.' -// }); -// } - -// reply.code(200).send({ -// success: true, -// message: 'Department data retrieved successfully.', -// data: department -// }); -// } catch (error) { -// console.error('Error fetching department data:', error); -// reply.code(500).send({ -// success: false, -// message: 'Failed to retrieve department data.', -// error: error.message, -// }); -// } -// }; - + exports.getallCompanyNames = async (req, reply) => { try { await City.find() @@ -293,32 +250,6 @@ exports.getallCompanyNames = async (req, reply) => { -// exports.getAllDepartmentsParticularFields = async (req, reply) => { -// try { -// const departments = await Department.find().exec(); - -// // Grouping the data -// const result = { -// cities: [...new Set(departments.map((doc) => doc.city))], -// zones: [...new Set(departments.map((doc) => doc.zone))], -// pincodes: [...new Set(departments.map((doc) => doc.pincode))], -// departments: [...new Set(departments.map((doc) => doc.departmentName))], -// states: [...new Set(departments.map((doc) => doc.state))], -// countries: [...new Set(departments.map((doc) => doc.country))], -// }; - -// // Sending the response -// reply.send({ -// status_code: 200, -// data: result, -// count: departments.length, -// }); -// } catch (err) { -// console.error(err); -// reply.send({ error: err.message }); -// } -// }; - exports.deletecityInfo = async (req, reply) => { try { @@ -451,73 +382,6 @@ exports.getallCompanyNames = async (req, reply) => { }; -// exports.addDesgination = async (request, reply) => { -// try { -// const { -// phone, -// city, -// firstName, -// lastName, -// departmentName, -// reportingManager, -// email, -// state, -// password, -// country, -// zone, -// address1, -// address2, -// pincode, -// desginationName, -// location, -// createdBy, -// updatedBy, -// } = request.body; - -// // Generate desginationId based on desginationName -// const prefix = departmentName.substring(0, 2).toUpperCase(); -// const desginationId = await generateDesginationId(prefix); - -// // Check if the phone is already registered -// const existingStore = await Desgination.findOne({ phone }); -// if (existingStore) { -// return reply.status(400).send({ message: 'Phone is already registered' }); -// } - -// // Hash the password -// const hashedPassword = await bcrypt.hash(password, 10); - -// // Create a new designation -// const desgination = new Desgination({ -// desginationId, -// city, -// firstName, -// lastName, -// email, -// reportingManager, -// departmentName, -// phone, -// address1, -// address2, -// services: { password: { bcrypt: hashedPassword } }, -// state, -// zone, -// country, -// pincode, -// desginationName, -// location, -// createdBy, -// updatedBy, -// }); - -// await desgination.save(); - -// reply.send({ desgination, message: 'Account Created Successfully' }); -// } catch (err) { -// reply.status(500).send({ message: err.message }); -// } -// }; - exports.addDepartment = async (request, reply) => { try { @@ -866,119 +730,6 @@ exports.editdepartment = async (request, reply) => { } }; -// exports.getAllDesignationsParticularFields = async (req, reply) => { -// try { -// const departments = await Desgination.find().exec(); - -// // Grouping the data -// const result = { -// cities: [...new Set(departments.map((doc) => doc.city))], -// zones: [...new Set(departments.map((doc) => doc.zone))], -// pincodes: [...new Set(departments.map((doc) => doc.pincode))], -// departments: [...new Set(departments.map((doc) => doc.departmentName))], -// states: [...new Set(departments.map((doc) => doc.state))], -// countries: [...new Set(departments.map((doc) => doc.country))], -// designations: [...new Set(departments.map((doc) => doc.desginationName))], -// reportingMangers: [...new Set(departments.map((doc) => doc.reportingManager))], - -// }; - -// // Sending the response -// reply.send({ -// status_code: 200, -// data: result, -// count: departments.length, -// }); -// } catch (err) { -// console.error(err); -// reply.send({ error: err.message }); -// } -// }; - -// const getLocationsByCityAndZone = async (city, zone) => { -// try { -// const matchCondition = { -// city: { $regex: `^${city.trim().toLowerCase()}$`, $options: "i" }, -// }; - -// // If a specific zone (not "ALL") is provided, filter by that zone -// if (zone.trim().toUpperCase() !== "ALL") { -// matchCondition.zone = zone.trim(); -// } - -// const result = await Zone.aggregate([ -// { -// $project: { -// city: { $toLower: { $trim: { input: "$city" } } }, -// zone: { $trim: { input: "$zone" } }, -// location: 1, -// }, -// }, -// { -// $match: matchCondition, -// }, -// { -// $group: { -// _id: "$city", -// locations: { $push: "$location" }, -// }, -// }, -// { -// $project: { -// _id: 0, -// city: "$_id", -// locations: { -// $reduce: { -// input: "$locations", -// initialValue: [], -// in: { $concatArrays: ["$$value", "$$this"] }, -// }, -// }, -// }, -// }, -// ]); - -// console.log("Query Result:", result); - -// if (result.length) { -// let locations = [...new Set(result[0].locations)]; // Remove duplicates - -// // Ensure "ALL" is always the first element -// if (!locations.includes("ALL")) { -// locations.unshift("ALL"); -// } - -// return { city, locations }; -// } else { -// return { city, locations: ["ALL"] }; // If no data, return only "ALL" -// } -// } catch (err) { -// console.error(err); -// throw new Error("Error fetching locations."); -// } -// }; - -// exports.getZonebasedLocations = async (req, reply) => { -// try { -// const { city, zone } = req.query; -// console.log("Received City:", `"${city}"`, "Received Zone:", `"${zone}"`); - -// if (!city || !zone) { -// return reply.status(400).send({ message: "City and zone are required." }); -// } - -// const locations = await getLocationsByCityAndZone(city.trim(), zone.trim()); - -// if (!locations) { -// return reply.send({ status_code: 404, message: "No data found." }); -// } - -// reply.send({ status_code: 200, data: locations }); -// } catch (err) { -// reply.status(500).send({ message: err.message }); -// } -// }; - const getLocationsByCityZoneOffice = async (city, zone, officeName) => { try { @@ -1142,68 +893,6 @@ exports.getZonebasedLocations = async (req, reply) => { } }; - // const getZonesByCitys = async (city) => { - // try { - // const result = await Zone.aggregate([ - // { - // $project: { - // city: { $trim: { input: "$city" } }, // Trim city field in DB - // zone: 1 // Keep zone field - // } - // }, - // { - // $match: { - // city: { $regex: `^${city.trim()}$`, $options: "i" }, // Trim & case-insensitive - // } - // }, - // { - // $group: { - // _id: { $toUpper: "$city" }, // Normalize city name - // zones: { $addToSet: "$zone" } // Collect unique zones - // } - // }, - // { - // $project: { - // _id: 0, // Exclude _id - // city: "$_id", // Return city name - // zones: 1 // Return collected zones - // } - // } - // ]); - - // // Add "ALL" to the zones array and sort it - // result.forEach(item => { - // item.zones = ["ALL", ...new Set(item.zones)].sort((a, b) => (a === "ALL" ? -1 : a - b)); - // }); - - // return result; - // } catch (err) { - // console.error("Error fetching zones:", err); - // throw new Error("Error fetching zones."); - // } - // }; - - - // exports.getZonesByCity = async (req, reply) => { - // try { - // const { city } = req.params; - - // if (!city || city.trim() === "") { - // return reply.status(400).send({ message: "City is required." }); - // } - - // const zones = await getZonesByCitys(city.trim()); // Trim input - - // if (zones.length === 0) { - // return reply.status(404).send({ message: "No zones found for the specified city." }); - // } - - // reply.send({ status_code: 200, data: zones }); - // } catch (err) { - // reply.status(500).send({ message: err.message }); - // } - // }; - const getZonesByCityAndOffice = async (city, officeName) => { @@ -1399,131 +1088,6 @@ exports.getZonesByCityAndOffice = async (req, reply) => { } }; - // const getDepartmentsByName = async (departmentName, city) => { - // try { - // const result = await Deparments.find({ - // departmentName: { $regex: `^${departmentName.trim()}$`, $options: "i" }, // Case-insensitive search - // city: { $regex: `^${city.trim()}$`, $options: "i" }, // Case-insensitive search - // }).lean(); // Convert to plain JSON - - // return result; - // } catch (err) { - // console.error("Error fetching department data:", err); - // throw new Error("Error fetching department data."); - // } - // }; - -// Updated helper function that accepts all three parameters -// const getDepartmentsByName = async (officeName, city, departmentName) => { -// try { -// // Trim all parameters -// const trimmedOfficeName = officeName.trim(); -// const trimmedCity = city.trim(); -// const trimmedDepartment = departmentName.trim(); - -// const query = { -// officeName: { $regex: trimmedOfficeName, $options: "i" }, -// departmentName: { $regex: trimmedDepartment, $options: "i" }, -// city: { $regex: trimmedCity, $options: "i" } -// }; - -// console.log("MongoDB Query:", JSON.stringify(query, null, 2)); - -// const result = await Deparments.find(query).lean(); - -// console.log("Query Result:", result); -// return result; -// } catch (err) { -// console.error("Error fetching department data:", err); -// throw new Error("Error fetching department data."); -// } -// }; - - - // API Route - // exports.getDepartments = async (req, reply) => { - // try { - // console.log("Request Params:", req.params); // Debugging log - - // let { departmentName, city, officeName } = req.params; - - // if (!departmentName || !city || !officeName) { - // return reply.status(400).send({ message: "Department Name, City, and Office Name are required." }); - // } - - // departmentName = departmentName.trim(); - // city = city.trim(); - // officeName = officeName.trim(); - - // // Note the order: officeName, city, departmentName - // const departments = await getDepartmentsByName(officeName, city, departmentName); - - // if (departments.length === 0) { - // return reply.status(404).send({ message: "No departments found for the specified parameters." }); - // } - - // reply.send({ status_code: 200, data: departments }); - // } catch (err) { - // console.error("API Error:", err); - // reply.status(500).send({ message: err.message }); - // } - // }; - -// const getDepartmentsByName = async (officeName, city, departmentName) => { -// try { -// const query = {}; - -// if (officeName && officeName.trim().toUpperCase() !== "ALL") { -// query.officeName = { $regex: officeName.trim(), $options: "i" }; -// } - -// if (city && city.trim().toUpperCase() !== "ALL") { -// query.city = { $regex: city.trim(), $options: "i" }; -// } - -// if (departmentName && departmentName.trim().toUpperCase() !== "ALL") { -// query.departmentName = { $regex: departmentName.trim(), $options: "i" }; -// } - -// console.log("MongoDB Query:", JSON.stringify(query, null, 2)); - -// const result = await Deparments.find(query).lean(); -// console.log("Query Result:", result); - -// return result; -// } catch (err) { -// console.error("Error fetching department data:", err); -// throw new Error("Error fetching department data."); -// } -// }; - -// exports.getDepartments = async (req, reply) => { -// try { -// console.log("Request Params:", req.params); - -// let { departmentName, city, officeName } = req.params; - -// if (!departmentName || !city || !officeName) { -// return reply.status(400).send({ -// message: "Department Name, City, and Office Name are required.", -// }); -// } - -// const departments = await getDepartmentsByName(officeName, city, departmentName); - -// if (departments.length === 0) { -// return reply.status(404).send({ -// message: "No departments found for the specified parameters.", -// }); -// } - -// reply.send({ status_code: 200, data: departments }); -// } catch (err) { -// console.error("API Error:", err); -// reply.status(500).send({ message: err.message }); -// } -// }; - exports.getDepartments = async (req, reply) => { @@ -1631,54 +1195,6 @@ const getDepartmentsByName = async (officeName, city, departmentName, employeeTy }; -// exports.getCitiesByOfficeName = async (req, reply) => { -// try { -// let { officeName } = req.params; - -// if (!officeName) { -// return reply.code(400).send({ error: "officeName is required" }); -// } - -// // Split by comma and normalize names -// let officeNames = officeName.split(',').map(name => -// name.trim().replace(/\s+/g, ' ') -// ); - -// // Handle "All" — fetch all cities from both collections -// if (officeNames.includes('All')) { -// const allCityDocs = await City.find().select("city -_id").lean(); -// const allBranchDocs = await Branch.find().select("city -_id").lean(); - -// const allCities = [...new Set([ -// ...allCityDocs.map(doc => doc.city), -// ...allBranchDocs.map(doc => doc.city), -// ])]; - -// return reply.send({ status_code: 200, data: allCities }); -// } - -// // Build regex conditions for each office name -// const regexConditions = officeNames.map(name => ({ -// officeName: { $regex: new RegExp(name.replace(/\s+/g, '\\s*'), 'i') } -// })); - -// // Query both collections -// const cityResults = await City.find({ $or: regexConditions }).select("city -_id").lean(); -// const branchResults = await Branch.find({ $or: regexConditions }).select("city -_id").lean(); - -// // Extract and merge unique city names -// const cityNames = [...new Set([ -// ...cityResults.map(c => c.city), -// ...branchResults.map(b => b.city) -// ])]; - -// reply.send({ status_code: 200, data: cityNames }); -// } catch (err) { -// console.error("Error fetching cities:", err); -// reply.send({ error: err.message }); -// } -// }; - exports.getCitiesByOfficeName = async (req, reply) => { try { let { officeName } = req.params; @@ -1806,55 +1322,6 @@ exports.getOffices = async (req, reply) => { } }; - -// exports.getOffices = async (req, reply) => { -// try { -// const { officeName, city } = req.params; - -// const filter = {}; - -// if (officeName && officeName !== 'ALL') { -// const officeNames = officeName.split(',').map(name => -// new RegExp(`^${name.trim()}$`, 'i') -// ); -// filter.officeName = { $in: officeNames }; -// } -// console.log("officeName",officeName) -// if (city && city !== 'ALL') { -// const cities = city.split(',').map(c => -// new RegExp(`^${c.trim()}$`, 'i') -// ); -// filter.city = { $in: cities }; -// } -// console.log("officeName",officeName) - -// const offices = await Deparments.find(filter).lean(); -// console.log(offices, "offices"); - -// const departmentNames = [...new Set(offices.map(o => o.departmentName))]; -// console.log(departmentNames, "departmentNames"); - -// reply.send({ -// status_code: 200, -// message: "Fetched successfully", -// data: departmentNames, -// }); - -// } catch (error) { -// console.error("Error in getOffices:", error); -// reply.code(500).send({ -// status_code: 500, -// message: "Internal server error", -// error: error.message, -// }); -// } -// }; - - - - - - // API route handler exports.getDepartmentsByCity = async (req, reply) => { try { const { city } = req.params; @@ -1970,107 +1437,6 @@ exports.getStaffDepartmentDetails = async (request, reply) => { }; - - - -// exports.updateBranchOrCompanyDetails = async (request, reply) => { -// try { -// const { id } = request.params; -// const updateData = request.body; -// let updatedDoc; - -// if (id.startsWith("AWBR")) { -// // Update Branch -// updatedDoc = await Branch.findOneAndUpdate( -// { branchId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); -// } else if (id.startsWith("AWCI")) { -// // Update City -// updatedDoc = await City.findOneAndUpdate( -// { cityId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); -// } else { -// return reply.code(400).send({ error: "Invalid ID format" }); -// } - -// if (!updatedDoc) { -// return reply.code(404).send({ message: "Record not found" }); -// } - -// return reply.send({ -// message: "Details updated successfully", -// data: updatedDoc, -// }); -// } catch (err) { -// request.log.error(err); -// return reply -// .code(500) -// .send({ error: "Failed to update details", details: err.message }); -// } -// }; - - -// exports.updateBranchOrCompanyDetails = async (request, reply) => { -// try { -// const { id } = request.params; -// const updateData = request.body; -// let updatedDoc; - -// if (id.startsWith("AWBR")) { -// // Update Branch -// updatedDoc = await Branch.findOneAndUpdate( -// { branchId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); - -// // Update department schema if office name matches -// if (updateData.city) { -// await Deparments.updateMany( -// { officeName: updatedDoc.officeName }, -// { $set: { city: updateData.city } } -// ); -// } -// } else if (id.startsWith("AWCI")) { -// // Update City -// updatedDoc = await City.findOneAndUpdate( -// { cityId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); - -// // Update department schema if office name matches -// if (updateData.city) { -// await Department.updateMany( -// { officeName: updatedDoc.officeName }, -// { $set: { city: updateData.city } } -// ); -// } -// } else { -// return reply.code(400).send({ error: "Invalid ID format" }); -// } - -// if (!updatedDoc) { -// return reply.code(404).send({ message: "Record not found" }); -// } - -// return reply.send({ -// message: "Details updated successfully", -// data: updatedDoc, -// }); -// } catch (err) { -// request.log.error(err); -// return reply -// .code(500) -// .send({ error: "Failed to update details", details: err.message }); -// } -// }; - - exports.updateBranchOrCompanyDetails = async (request, reply) => { try { const { id } = request.params; diff --git a/src/routes/adminRoute.js b/src/routes/adminRoute.js index 184370ea..bb7e74db 100644 --- a/src/routes/adminRoute.js +++ b/src/routes/adminRoute.js @@ -211,23 +211,6 @@ fastify.route({ }); -// 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, -// }); diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index 6da23f7c..6cf64308 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -473,21 +473,7 @@ fastify.route({ handler: departmentController.editdepartment, }); - // fastify.get("/api/getalldesignationsParticularFileds", { - // schema: { - // tags: ["Department"], - // description: "This is for Get all Designation particular fileds", - // summary: "This is for to Get all Designation particular fields", - - // security: [ - // { - // basicAuth: [], - // }, - // ], - // }, - // //preHandler: fastify.auth([fastify.authenticate]), - // handler: departmentController.getAllDesignationsParticularFields, - // }); + fastify.route({ method: "GET", @@ -527,25 +513,7 @@ fastify.route({ handler:departmentController.getLocationsByZone }); - // fastify.route({ - // method: "GET", - // url: "/api/zonebasedcity/:city/:officeName", - // schema: { - // tags: ["Department"], - // description: "Get the zones by city", - // summary: "Get the zones by city", - // params: { - // type: "object", - // properties: { - // city: { type: "string" }, - // officeName: { type: "string" }, - - // }, - // }, - // }, - // handler:departmentController.getZonesByCity - // }); - + fastify.route({ method: "GET", url: "/api/zonebasedcity/:city/:officeName", diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 307fbc25..cd46810f 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -53,38 +53,6 @@ fastify.get("/api/getAllDepartments/:officeName", { }); - // fastify.get("/api/getTeamMembers/:officeName/:city/:departmentName/:departmentId", { - // schema: { - // description: "Get all team members under a specific department", - // tags: ["Installation"], - // summary: "Get Team Members by Department ID", - // params: { - // type: "object", - // properties: { - // officeName: { - // type: "string", - // description: "fetch team members from" - // }, - // city: { - // type: "string", - // description: "fetch team members from" - // }, - // departmentName:{ - // type: "string", - // description: "Department Name to fetch team members from" - // }, - // departmentId: { - // type: "string", - // description: "Department ID to fetch team members from" - // } - // }, - - // required: ["departmentId"] - // }, - // }, - // handler: installationController.getTeamMembers - // }); - fastify.get("/api/getTeamMembers/:officeName/:city/:departmentId", { schema: { description: "Get all team members under a specific department", @@ -615,67 +583,12 @@ fastify.put('/api/Updatetanksdimensisons/:customerId/:teamMemberId/:hardwareId/: } } }, - // response: { - // 200: { - // type: 'object', - // properties: { - // success: { type: 'boolean' }, - // message: { type: 'string' }, - // orderMatchedCount: { type: 'integer' }, - // orderModifiedCount: { type: 'integer' }, - // masterModifiedCount: { type: 'integer' }, - // slaveModifiedCount: { type: 'integer' } - // } - // }, - // 400: { - // type: 'object', - // properties: { - // success: { type: 'boolean' }, - // message: { type: 'string' } - // } - // }, - // 500: { - // type: 'object', - // properties: { - // success: { type: 'boolean' }, - // message: { type: 'string' } - // } - // } - // } + }, handler: installationController.updateWorkStatusAndProductStatus } ); -// fastify.put('/api/tanks/:customerId/:teamMemberId/:hardwareId/:tankHardwareId', { -// schema: { -// tags: ['Installation'], -// summary: 'Update tank dimensions', -// description: 'Edit tank details (height, width, length) by customerId, teamMemberId, hardwareId and tankHardwareId.', -// params: { -// type: 'object', -// required: ['customerId', 'teamMemberId', 'hardwareId', 'tankHardwareId'], -// properties: { -// customerId: { type: 'string', description: 'Customer ID' }, -// teamMemberId: { type: 'string', description: 'Team member ID' }, -// hardwareId: { type: 'string', description: 'Master hardwareId' }, -// tankHardwareId: { type: 'string', description: 'Tank hardwareId' } -// } -// }, -// body: { -// type: 'object', -// //required: ['height', 'width', 'length'], -// properties: { -// height: { type: 'number', description: 'New tank height (in cm)' }, -// width: { type: 'number', description: 'New tank width (in cm)' }, -// length: { type: 'number', description: 'New tank length (in cm)' } -// } -// }, - -// }, -// handler : installationController.editTankDimensions -// }); - fastify.post( '/api/insensors/media/:customerId', @@ -721,31 +634,7 @@ fastify.post( // at least one of video, material, workStatus required }, - // response: { - // 200: { - // type: 'object', - // properties: { - // success: { type: 'boolean' }, - // message: { type: 'string' }, - // data: { - // type: 'object', - // description: 'Updated Insensor document' - // } - // } - // }, - // 400: { - // type: 'object', - // properties: { success: { type: 'boolean' }, message: { type: 'string' } } - // }, - // 404: { - // type: 'object', - // properties: { success: { type: 'boolean' }, message: { type: 'string' } } - // }, - // 500: { - // type: 'object', - // properties: { success: { type: 'boolean' }, message: { type: 'string' } } - // } - // } + }, handler: installationController.addMediaToInsensor } @@ -892,23 +781,7 @@ fastify.post( handler: installationController.getIotDataByCustomerAndHardwareId, }); - // fastify.get("/api/getraiseAticket/:customerId/:connected_to", { - // schema: { - // description: "Raise A Ticket for Support", - // tags: ["Support"], - // summary: "Raise A Ticket for Support", - // params: { - // type: "object", - // properties: { - // customerId: { type: "string" }, - // connected_to: { type: "string" }, - - // }, - // required: [ "customerId"], - // }, - // }, - // handler: installationController.raiseATicket, - // }); + fastify.get("/api/getraiseAticketBuildingDetails/:customerId/:connected_to/:installationId", { schema: { @@ -1315,27 +1188,7 @@ fastify.post( handler: installationController.moveIssueToCategory }); - // fastify.get('/api/support/categorizedIssues/:supportId/:category', { - // schema: { - // description: 'Get all issues in a particular category for a support record', - // tags: ['Support'], - // summary: 'Fetch issues by category', - // params: { - // type: 'object', - // required: ['supportId', 'category'], - // properties: { - // supportId: { type: 'string' }, - // //customerId: { type: 'string' }, - // category: { - // type: 'string', - // enum: ['Power Outage', 'Level1', 'Pending', 'Onsite Issues'] // your allowed categories - // } - // } - // }, - - // }, - // handler: installationController.particularCategory - // }); + fastify.get('/api/support/categorizedIssues/:supportId/:category', { schema: {