mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 05:42:27 +00:00
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
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 } from '~/common/decorators';
|
|
import { AccessTokenGuard } from '~/common/guards';
|
|
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('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,
|
|
@Headers(DEVICE_ID_HEADER) deviceId: string,
|
|
) {
|
|
return this.userService.updateNotificationSettings(user.sub, data, deviceId);
|
|
}
|
|
}
|