Skip to content

Commit

Permalink
Update user with id from cookie jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
esteban-gs committed Nov 7, 2023
1 parent f3bd587 commit 986aa88
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server/src/acccount-manager/account-manager.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,16 @@ export class AccountManagerController {
}),
)
async upsertProfile(
@Request() request: AuthedRequest,
@Param('id') id: number,
@UploadedFile()
file: Express.Multer.File,
): Promise<ReturnUserDto | BadRequestException> {
const { user } = request;
if (user.id !== id) {
throw new BadRequestException('You can only update your own user');
}

if (/\.(jpe?g|png|gif)$/i.test(file.filename)) {
return new BadRequestException(
'Only valid image extensions allowed (.jpg, .jpeg, .png, .gif)',
Expand Down Expand Up @@ -269,9 +275,17 @@ export class AccountManagerController {
@UseGuards(CookieAuthGuard)
@MapTo(ReturnUserDto)
@Put('users/:id')
async update(@Param('id') id: number, @Body() updateUserDto: UpdateUserDto) {
const user = await this.usersService.findOne(id);
if (!user) {
async update(
@Request() request: AuthedRequest,
@Param('id') id: number,
@Body() updateUserDto: UpdateUserDto,
) {
const { user } = request;
if (user.id !== id) {
throw new BadRequestException('You can only update your own user');
}
const dbUser = await this.usersService.findOne(id);
if (!dbUser) {
throw new BadRequestException('User not found');
}

Expand Down

0 comments on commit 986aa88

Please sign in to comment.