mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 19:51:46 +00:00
- 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.
67 lines
2.6 KiB
TypeScript
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);
|
|
}
|
|
}
|