Files
zod-backend/src/user/controllers/user.controller.ts
Abdalhamid Alhamad 145e6c62b8 feat: implement KYC and card notification events
- Added KycNotificationListener to handle notifications for KYC approval and rejection events.
- Introduced CardNotificationListener to manage notifications for card creation and blocking events.
- Enhanced CardService to emit events for card creation and blocking, integrating with the new notification system.
- Updated notification constants and interfaces to include new KYC and card-related events.
- Improved notification message formatting and added localization support for new events.
2026-01-14 12:31:48 +03:00

67 lines
2.6 KiB
TypeScript

import { Body, Controller, Get, 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 { 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 { NotificationsSettingsResponseDto } from '../dtos/response/notifications-settings.response.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);
}
@Get('notifications-settings')
@HttpCode(HttpStatus.OK)
@ApiDataResponse(NotificationsSettingsResponseDto)
async getNotificationSettings(@AuthenticatedUser() { sub }: IJwtPayload) {
const user = await this.userService.findUserOrThrow({ id: sub });
return ResponseFactory.data(new NotificationsSettingsResponseDto({
isPushEnabled: user.isPushEnabled ?? true,
}));
}
@Patch('notifications-settings')
@HttpCode(HttpStatus.NO_CONTENT)
async updateNotificationSettings(
@AuthenticatedUser() user: IJwtPayload,
@Body() data: UpdateNotificationsSettingsRequestDto,
) {
return this.userService.updateNotificationSettings(user.sub, data, data.deviceId);
}
}