From 7b712d9ee91bdf3e0016c5d05b2b8046c412fd8d Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Wed, 27 Nov 2024 17:20:17 +0700 Subject: [PATCH] update profile and password --- src/controllers/user.ts | 19 ++++--------------- src/routes/private.ts | 4 ++-- src/routes/public.ts | 1 + 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/controllers/user.ts b/src/controllers/user.ts index e79e52f..cd9214e 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -1,4 +1,5 @@ -import { Request, Response, NextFunction, Application } from "express"; +import { Response, NextFunction, Application } from "express"; +import { Request } from "express-jwt"; import { ReturnHelper } from "../helpers/express/return"; import { OrmHelper } from "../helpers/orm"; import { User } from "../entity/users"; @@ -161,12 +162,6 @@ export class UserController { #swagger.security = [{ "bearerAuth": [] }] - #swagger.parameters['id'] = { - in: 'path', - description: 'User ID.', - required: true, - type: 'string' - } #swagger.requestBody = { required: true, @@ -188,7 +183,7 @@ export class UserController { name: Joi.string().max(64).required().label('Name'), }); - req.body.id = req.params['id']; + req.body.id = req.auth.data.id; const param: User = await schema.validateAsync(req.body); @@ -221,12 +216,6 @@ export class UserController { #swagger.security = [{ "bearerAuth": [] }] - #swagger.parameters['id'] = { - in: 'path', - description: 'User ID.', - required: true, - type: 'string' - } #swagger.requestBody = { required: true, @@ -247,7 +236,7 @@ export class UserController { retype_password: Joi.ref('password'), }); - req.body.id = req.params['id']; + req.body.id = req.auth.data.id; const param: User = await schema.validateAsync(req.body); diff --git a/src/routes/private.ts b/src/routes/private.ts index 5f523c8..8d9bd32 100644 --- a/src/routes/private.ts +++ b/src/routes/private.ts @@ -16,8 +16,8 @@ export class RoutePrivate { app.get('/api/user/list', UserController.list) app.post('/api/user/create', UserController.create) app.put('/api/user/update/:id', UserController.update) - app.put('/api/user/update_profile/:id', UserController.updateProfile) - app.put('/api/user/update_password/:id', UserController.updatePassword) + app.put('/api/user/update_profile', UserController.updateProfile) + app.put('/api/user/update_password', UserController.updatePassword) app.delete('/api/user/delete/:id', UserController.delete) app.put('/api/user/restore/:id', UserController.restore) diff --git a/src/routes/public.ts b/src/routes/public.ts index be5d0c7..68a3b3c 100644 --- a/src/routes/public.ts +++ b/src/routes/public.ts @@ -6,6 +6,7 @@ export class RoutePublic { static setup(app: express.Application) { app.post('/api/login', AuthController.login) + app.post('/api/reset_password', AuthController.login) app.put('/api/logout/:refresh_token', AuthController.logout) app.put('/api/renew_token/:refresh_token', AuthController.renewToken)