mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
37 lines
1.4 KiB
TypeScript
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);
|
|
}
|
|
}
|