forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.controller.ts
More file actions
33 lines (29 loc) · 1.14 KB
/
Copy pathnotifications.controller.ts
File metadata and controls
33 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Controller, Get, Post, Param, Query, UseGuards, Req } from '@nestjs/common';
import { NotificationsService } from './notifications.service';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { PaginationDto } from '../../common/dto/pagination.dto';
@Controller('api/notifications')
@UseGuards(JwtAuthGuard)
export class NotificationsController {
constructor(private readonly notificationsService: NotificationsService) {}
@Get()
async list(
@Req() req: any,
@Query() paginationDto: PaginationDto,
@Query('unread') unread?: string,
) {
const userId = req.user?.userId;
const unreadBool = typeof unread === 'string' ? unread === 'true' : undefined;
return this.notificationsService.list(userId, paginationDto.page, paginationDto.limit, unreadBool);
}
@Post(':id/read')
async markRead(@Req() req: any, @Param('id') id: string) {
const userId = req.user?.userId;
return this.notificationsService.markRead(userId, id);
}
@Get('unread-count')
async unreadCount(@Req() req: any) {
const userId = req.user?.userId;
return this.notificationsService.unreadCount(userId);
}
}