feat: working on edit profile ticket

This commit is contained in:
Abdalhamid Alhamad
2025-08-05 17:53:38 +03:00
parent 1e2b859b92
commit 275984954e
37 changed files with 298 additions and 275 deletions

View File

@ -1,20 +1,52 @@
import { Body, Controller, Headers, HttpCode, HttpStatus, Patch, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Headers, HttpCode, HttpStatus, Patch, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { VerifyOtpRequestDto } from '~/auth/dtos/request';
import { UserResponseDto } from '~/auth/dtos/response';
import { IJwtPayload } from '~/auth/interfaces';
import { DEVICE_ID_HEADER } from '~/common/constants';
import { AuthenticatedUser, Public } from '~/common/decorators';
import { AuthenticatedUser } from '~/common/decorators';
import { AccessTokenGuard } from '~/common/guards';
import { SetInternalPasswordRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
import { ApiDataResponse } from '~/core/decorators';
import { ResponseFactory } from '~/core/utils';
import { UpdateNotificationsSettingsRequestDto, UpdateUserRequestDto } from '../dtos/request';
import { UpdateEmailRequestDto } from '../dtos/request/update-email.request.dto';
import { UserService } from '../services';
@Controller('users')
@ApiTags('Users')
@Controller('profile')
@ApiTags('User - Profile')
@UseGuards(AccessTokenGuard)
@ApiBearerAuth()
export class UserController {
constructor(private userService: UserService) {}
@Get()
@HttpCode(HttpStatus.OK)
@ApiDataResponse(UserResponseDto)
async getProfile(@AuthenticatedUser() { sub }: IJwtPayload) {
const user = await this.userService.findUserOrThrow({ id: sub }, true);
return ResponseFactory.data(new UserResponseDto(user));
}
@Patch('')
@HttpCode(HttpStatus.NO_CONTENT)
async updateProfile(@AuthenticatedUser() user: IJwtPayload, @Body() data: UpdateUserRequestDto) {
return this.userService.updateUser(user.sub, data);
}
@Patch('email')
@HttpCode(HttpStatus.NO_CONTENT)
async updateEmail(@AuthenticatedUser() user: IJwtPayload, @Body() data: UpdateEmailRequestDto) {
return this.userService.updateUserEmail(user.sub, data.email);
}
@Patch('verify-email')
@HttpCode(HttpStatus.NO_CONTENT)
async verifyEmail(@AuthenticatedUser() user: IJwtPayload, @Body() { otp }: VerifyOtpRequestDto) {
return this.userService.verifyEmail(user.sub, otp);
}
@Patch('notifications-settings')
@HttpCode(HttpStatus.NO_CONTENT)
async updateNotificationSettings(
@AuthenticatedUser() user: IJwtPayload,
@Body() data: UpdateNotificationsSettingsRequestDto,
@ -22,11 +54,4 @@ export class UserController {
) {
return this.userService.updateNotificationSettings(user.sub, data, deviceId);
}
@Post('internal/set-password')
@Public()
@HttpCode(HttpStatus.NO_CONTENT)
async setPassword(@Body() data: SetInternalPasswordRequestDto) {
return this.userService.setCheckerPassword(data);
}
}