diff --git a/src/controllers/admincontroller.js b/src/controllers/admincontroller.js index af787c81..73e979db 100644 --- a/src/controllers/admincontroller.js +++ b/src/controllers/admincontroller.js @@ -88,6 +88,38 @@ exports.adminSignUp = async (request, reply) => { } }; +exports.editAdmin = async (request, reply) => { + try { + const { customerId } = request.params; + const { + + phone, + username, + picture, + + } = request.body; + + + const existing = await Admin.findOne({ customerId }); + if (!existing) { + return reply.status(404).send({ message: 'City not found' }); + } + + existing.phone = phone || existing.phone; + existing.username = username || existing.username; + existing.picture = picture || existing.picture; + + + + + await existing.save(); + + reply.send({ message: 'Admin user updated successfully' }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; + // Admin Login Function (With Phone Number) // exports.adminLogin = async (request, reply) => { diff --git a/src/routes/adminRoute.js b/src/routes/adminRoute.js index 6a03c812..1d0c1509 100644 --- a/src/routes/adminRoute.js +++ b/src/routes/adminRoute.js @@ -31,6 +31,30 @@ fastify.route({ 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: {