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

91 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-05-16 09:23:59 +00:00
import { TemplateDto } from '@dtos/template.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 { TemplateService } from '@services/template.service';
2022-05-23 05:05:59 +00:00
import { TemplateApiDefinition } from '@think/domains';
2022-02-20 11:51:55 +00:00
@Controller('template')
export class TemplateController {
constructor(private readonly templateService: TemplateService) {}
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(TemplateApiDefinition.public.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
2022-05-23 05:05:59 +00:00
async getPublicTemplates(@Query() qurey) {
return this.templateService.getPublicTemplates(qurey);
2022-02-20 11:51:55 +00:00
}
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(TemplateApiDefinition.own.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
2022-05-23 05:05:59 +00:00
async getOwnTemplates(@Request() req, @Query() qurey) {
return this.templateService.getOwnTemplates(req.user, qurey);
2022-02-20 11:51:55 +00:00
}
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(TemplateApiDefinition.add.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
2022-05-23 05:05:59 +00:00
async create(@Request() req, @Body() dto: TemplateDto) {
return await this.templateService.create(req.user, dto);
2022-02-20 11:51:55 +00:00
}
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(TemplateApiDefinition.updateById.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
2022-05-23 05:05:59 +00:00
async updateTemplat(@Request() req, @Body() dto: TemplateDto & { id: string }) {
return await this.templateService.updateTemplate(req.user, dto.id, dto);
2022-02-20 11:51:55 +00:00
}
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(TemplateApiDefinition.getDetailById.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
2022-05-23 05:05:59 +00:00
@UseGuards(JwtGuard)
async getTemplate(@Request() req, @Param('id') id) {
return this.templateService.getTemplate(req.user, id);
2022-02-20 11:51:55 +00:00
}
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(TemplateApiDefinition.deleteById.server)
2022-02-20 11:51:55 +00:00
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
2022-05-23 05:05:59 +00:00
async deleteTemplat(@Request() req, @Param('id') documentId) {
return await this.templateService.deleteTemplate(req.user, documentId);
2022-02-20 11:51:55 +00:00
}
}