add update user api

This commit is contained in:
JakkrapartXD 2026-01-14 16:29:18 +07:00
parent c411f2a8a4
commit 5d508c4731
3 changed files with 64 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request } from 'tsoa';
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request, Put } from 'tsoa';
import { UserService } from '../services/user.service';
import {
UserResponse,
@ -36,6 +36,23 @@ export class UserController {
return await this.userService.getUserProfile(token);
}
@Put('me')
@Security('jwt')
@SuccessResponse('200', 'Profile updated successfully')
@Response('401', 'Invalid or expired token')
@Response('400', 'Validation error')
public async updateProfile(@Request() request: any, @Body() body: ProfileUpdate): Promise<ProfileUpdateResponse> {
const { error } = profileUpdateSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await this.userService.updateProfile(token, body);
}
/**
* Change password
* @summary Change user password using old password