think/packages/server/src/controllers/comment.controller.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-05-16 09:23:59 +00:00
import { CommentDto, UpdateCommentDto } from '@dtos/comment.dto';
import { JwtGuard } from '@guard/jwt.guard';
2022-02-20 11:51:55 +00:00
import {
2022-05-16 09:23:59 +00:00
Body,
ClassSerializerInterceptor,
2022-02-20 11:51:55 +00:00
Controller,
2022-05-23 05:05:59 +00:00
Delete,
2022-02-20 11:51:55 +00:00
Get,
HttpCode,
2022-05-16 09:23:59 +00:00
HttpStatus,
Param,
2022-05-23 05:05:59 +00:00
Patch,
2022-02-20 11:51:55 +00:00
Post,
Query,
Request,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { CommentService } from '@services/comment.service';
2022-05-23 05:05:59 +00:00
import { CommentApiDefinition } from '@think/domains';
2022-02-20 11:51:55 +00:00
@Controller('comment')
export class CommentController {
constructor(private readonly commentService: CommentService) {}
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(CommentApiDefinition.add.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async create(@Request() req, @Body() dto: CommentDto) {
const userAgent = req.headers['user-agent'];
return await this.commentService.create(req.user, userAgent, dto);
}
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
@Patch(CommentApiDefinition.update.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async updateComment(@Request() req, @Body() dto: UpdateCommentDto) {
return await this.commentService.updateComment(req.user, dto);
}
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
@Delete(CommentApiDefinition.delete.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
async deleteComment(@Request() req, @Param('id') documentId) {
return await this.commentService.deleteComment(req.user, documentId);
}
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(CommentApiDefinition.documents.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
2022-05-24 09:33:30 +00:00
async getArticleComments(@Param('documentId') documentId, @Query() qurey) {
2022-02-20 11:51:55 +00:00
return this.commentService.getDocumentComments(documentId, qurey);
}
}