diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index 296f7d51..8c175a4b 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -2035,87 +2035,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")) { -// // Find existing Branch before update -// const existing = await Branch.findOne({ branchId: id }); - -// updatedDoc = await Branch.findOneAndUpdate( -// { branchId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); - -// // 🔄 Cascade update to Department employees if city/officeName changed -// if (updatedDoc && existing) { -// if ( -// (updateData.city && updateData.city !== existing.city) || -// (updateData.officeName && updateData.officeName !== existing.officeName) -// ) { -// await Deparments.updateMany( -// { officeName: existing.officeName, city: existing.city }, -// { -// $set: { -// city: updateData.city || existing.city, -// officeName: updateData.officeName || existing.officeName, -// }, -// } -// ); -// } -// } -// } else if (id.startsWith("AWCI")) { -// // Find existing City before update -// const existing = await City.findOne({ cityId: id }); - -// updatedDoc = await City.findOneAndUpdate( -// { cityId: id }, -// { ...updateData, updatedAt: new Date() }, -// { new: true } -// ); - -// // 🔄 Cascade update to Department employees if city/officeName changed -// if (updatedDoc && existing) { -// if ( -// (updateData.city && updateData.city !== existing.city) || -// (updateData.officeName && updateData.officeName !== existing.officeName) -// ) { -// await Deparments.updateMany( -// { officeName: existing.officeName, city: existing.city }, -// { -// $set: { -// city: updateData.city || existing.city, -// officeName: updateData.officeName || existing.officeName, -// }, -// } -// ); -// } -// } -// } 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; @@ -2138,7 +2057,7 @@ exports.updateBranchOrCompanyDetails = async (request, reply) => { (updateData.city && updateData.city !== existing.city) || (updateData.officeName && updateData.officeName !== existing.officeName) ) { - await Departments.updateMany( + await Deparments.updateMany( { officeName: existing.officeName, city: existing.city }, { $set: { @@ -2149,7 +2068,6 @@ exports.updateBranchOrCompanyDetails = async (request, reply) => { ); } } - } else if (id.startsWith("AWCI")) { // Find existing City before update const existing = await City.findOne({ cityId: id }); @@ -2166,7 +2084,7 @@ exports.updateBranchOrCompanyDetails = async (request, reply) => { (updateData.city && updateData.city !== existing.city) || (updateData.officeName && updateData.officeName !== existing.officeName) ) { - await Departments.updateMany( + await Deparments.updateMany( { officeName: existing.officeName, city: existing.city }, { $set: { @@ -2185,36 +2103,14 @@ exports.updateBranchOrCompanyDetails = async (request, reply) => { return reply.code(404).send({ message: "Record not found" }); } - // ✅ Handle profile picture update if provided - if (updateData.picture) { - const supportedFormats = ["jpg", "jpeg", "png"]; - const fileExtension = updateData.picture.split(".").pop().toLowerCase(); - - if (!supportedFormats.includes(fileExtension)) { - return reply.code(400).send({ - error: "Invalid file format", - message: "Picture must be a JPEG, PNG, or JPG image" - }); - } - - await CompanyProfilePicture.findOneAndUpdate( - { customerId: id }, - { customerId: id, picture: updateData.picture }, - { upsert: true, new: true } - ); - } - - return reply.send({ message: "Details updated successfully", data: updatedDoc, - picture: updateData.picture || null }); - } catch (err) { request.log.error(err); return reply .code(500) .send({ error: "Failed to update details", details: err.message }); } -}; \ No newline at end of file +}; diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index b7c1238c..99bba32f 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -242,8 +242,6 @@ fastify.route({ latitude: { type: "number" }, googleLocation: { type: "string" }, gstNo: { type: "string" }, - picture: { type: "string" } - }, additionalProperties: true, // allow extra fields if needed },