2022-05-16 09:23:59 +00:00
|
|
|
import { JwtGuard } from '@guard/jwt.guard';
|
2022-02-20 11:51:55 +00:00
|
|
|
import {
|
2022-05-16 09:23:59 +00:00
|
|
|
ClassSerializerInterceptor,
|
2022-02-20 11:51:55 +00:00
|
|
|
Controller,
|
|
|
|
Get,
|
|
|
|
HttpCode,
|
2022-05-16 09:23:59 +00:00
|
|
|
HttpStatus,
|
2022-02-20 11:51:55 +00:00
|
|
|
Param,
|
2022-05-16 09:23:59 +00:00
|
|
|
Post,
|
|
|
|
Query,
|
2022-02-20 11:51:55 +00:00
|
|
|
Request,
|
|
|
|
UseGuards,
|
|
|
|
UseInterceptors,
|
|
|
|
} from '@nestjs/common';
|
|
|
|
import { MessageService } from '@services/message.service';
|
|
|
|
|
|
|
|
@Controller('message')
|
|
|
|
export class MessageController {
|
|
|
|
constructor(private readonly messageService: MessageService) {}
|
|
|
|
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
@Get('/unread')
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getUnreadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getMessages(req.user, false, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
@Get('/read')
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getReadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getMessages(req.user, true, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
@Get('/all')
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getAllReadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getAllMessages(req.user, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
|
|
@Post('/read/:id')
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async updateComment(@Request() req, @Param('id') messageId) {
|
|
|
|
return await this.messageService.readMessage(req.user, messageId);
|
|
|
|
}
|
|
|
|
}
|