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';
|
2022-05-23 05:05:59 +00:00
|
|
|
import { MessageApiDefinition } from '@think/domains';
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
@Controller('message')
|
|
|
|
export class MessageController {
|
|
|
|
constructor(private readonly messageService: MessageService) {}
|
|
|
|
|
2022-05-23 05:05:59 +00:00
|
|
|
/**
|
|
|
|
* 获取未读消息
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-05-23 05:05:59 +00:00
|
|
|
@Get(MessageApiDefinition.getUnread.server)
|
2022-02-20 11:51:55 +00:00
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getUnreadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getMessages(req.user, false, query);
|
|
|
|
}
|
|
|
|
|
2022-05-23 05:05:59 +00:00
|
|
|
/**
|
|
|
|
* 获取已读消息
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-05-23 05:05:59 +00:00
|
|
|
@Get(MessageApiDefinition.getRead.server)
|
2022-02-20 11:51:55 +00:00
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getReadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getMessages(req.user, true, query);
|
|
|
|
}
|
|
|
|
|
2022-05-23 05:05:59 +00:00
|
|
|
/**
|
|
|
|
* 获取所有消息
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-05-23 05:05:59 +00:00
|
|
|
@Get(MessageApiDefinition.getAll.server)
|
2022-02-20 11:51:55 +00:00
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async getAllReadMessages(@Request() req, @Query() query) {
|
|
|
|
return this.messageService.getAllMessages(req.user, query);
|
|
|
|
}
|
|
|
|
|
2022-05-23 05:05:59 +00:00
|
|
|
/**
|
|
|
|
* 将消息标记为已读
|
|
|
|
*/
|
2022-02-20 11:51:55 +00:00
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2022-05-23 05:05:59 +00:00
|
|
|
@Post(MessageApiDefinition.readMessage.server)
|
2022-02-20 11:51:55 +00:00
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
@UseGuards(JwtGuard)
|
|
|
|
async updateComment(@Request() req, @Param('id') messageId) {
|
|
|
|
return await this.messageService.readMessage(req.user, messageId);
|
|
|
|
}
|
|
|
|
}
|