mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
feat: working on edit profile ticket
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user