ashok 1 month ago
commit 76eef3d01c

@ -1866,4 +1866,46 @@ exports.getCitiesBasedState = async (request, reply) => {
} catch (err) { } catch (err) {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: 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 }
);
} 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 });
}
};

@ -207,6 +207,46 @@ fastify.route({
} }
}, },
handler: departmentController.getDetails handler: departmentController.getDetails
});
fastify.route({
method: "PUT",
url: "/api/updateBranchOrCompanydetails/:id",
schema: {
tags: ["Department"],
description: "Update details of a branch or city",
summary: "Edit department details by branchId or cityId",
params: {
type: "object",
properties: {
id: { type: "string" }, // branchId or cityId
},
required: ["id"],
},
body: {
type: "object",
properties: {
phone: { type: "string" },
land_line_number: { type: "string" },
officeName: { type: "string" },
office_address1: { type: "string" },
address2: { type: "string" },
email: { type: "string" },
pincode: { type: "string" },
zone: { type: "string" },
city: { type: "string" },
state: { type: "string" },
country: { type: "string" },
nameoftheContactPerson: { type: "string" },
location: { type: "array", items: { type: "string" } },
longitude: { type: "number" },
latitude: { type: "number" },
googleLocation: { type: "string" },
gstNo: { type: "string" }
},
additionalProperties: true, // allow extra fields if needed
},
},
handler: departmentController.updateBranchOrCompanyDetails
}); });
fastify.route({ fastify.route({
method: "GET", method: "GET",

Loading…
Cancel
Save