Files
zod-backend/src/common/modules/notification/controllers/notifications.controller.ts
2025-01-06 16:47:43 +03:00

37 lines
1.4 KiB
TypeScript

import { Controller, Get, HttpCode, HttpStatus, Post, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { IJwtPayload } from '~/auth/interfaces';
import { AuthenticatedUser } from '~/common/decorators';
import { AccessTokenGuard } from '~/common/guards';
import { PageOptionsRequestDto } from '~/core/dtos';
import { NotificationsPageResponseDto } from '../dtos/response';
import { NotificationsService } from '../services/notifications.service';
@Controller('notifications')
@ApiTags('Notifications')
@ApiBearerAuth()
export class NotificationsController {
constructor(private readonly notificationsService: NotificationsService) {}
@Get()
@UseGuards(AccessTokenGuard)
@ApiResponse({ type: NotificationsPageResponseDto })
async getNotifications(@AuthenticatedUser() { sub }: IJwtPayload, @Query() pageOptionsDto: PageOptionsRequestDto) {
const { notifications, count, unreadCount } = await this.notificationsService.getNotifications(sub, pageOptionsDto);
return new NotificationsPageResponseDto(notifications, {
itemCount: count,
unreadCount,
page: pageOptionsDto.page,
size: pageOptionsDto.size,
});
}
@Post('mark-as-read')
@UseGuards(AccessTokenGuard)
@HttpCode(HttpStatus.NO_CONTENT)
markAsRead(@AuthenticatedUser() { sub }: IJwtPayload) {
return this.notificationsService.markAsRead(sub);
}
}