add controller
This commit is contained in:
parent
619a59e33e
commit
552cbf2e57
@ -10,3 +10,11 @@ export enum PostOrder {
|
||||
COMMENTCOUNT = 'commentCount',
|
||||
CUSTOM = 'custom',
|
||||
}
|
||||
|
||||
export const DEFAULT_VALIDATION_CONFIG = Object.freeze({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
forbidUnknownValues: true,
|
||||
validationError: { target: false },
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
|
||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||
|
||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
||||
import { CreateCategoryDto, QueryCategoryDto, UpdateCategoryDto } from '../dtos/category.dto';
|
||||
import { CategoryService } from '../services';
|
||||
|
||||
@ -32,15 +33,7 @@ export class CategoryController {
|
||||
@Get()
|
||||
@SerializeOptions({ groups: ['category-list'] })
|
||||
async list(
|
||||
@Query(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
forbidUnknownValues: true,
|
||||
validationError: { target: false },
|
||||
}),
|
||||
)
|
||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
||||
options: QueryCategoryDto,
|
||||
) {
|
||||
return this.service.paginate(options);
|
||||
@ -57,11 +50,7 @@ export class CategoryController {
|
||||
async store(
|
||||
@Body(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
forbidUnknownValues: true,
|
||||
validationError: { target: false },
|
||||
...DEFAULT_VALIDATION_CONFIG,
|
||||
groups: ['create'],
|
||||
}),
|
||||
)
|
||||
@ -75,11 +64,7 @@ export class CategoryController {
|
||||
async update(
|
||||
@Body(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
forbidUnknownValues: true,
|
||||
validationError: { target: false },
|
||||
...DEFAULT_VALIDATION_CONFIG,
|
||||
groups: ['update'],
|
||||
}),
|
||||
)
|
||||
|
@ -17,6 +17,8 @@ import { CreatePostDto, QueryPostDto, UpdatePostDto } from '@/modules/content/dt
|
||||
import { PostService } from '@/modules/content/services/post.service';
|
||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||
|
||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
||||
|
||||
@UseInterceptors(AppInterceptor)
|
||||
@Controller('posts')
|
||||
export class PostController {
|
||||
@ -25,15 +27,7 @@ export class PostController {
|
||||
@Get()
|
||||
@SerializeOptions({ groups: ['post-list'] })
|
||||
async list(
|
||||
@Query(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidUnknownValues: true,
|
||||
forbidNonWhitelisted: true,
|
||||
validationError: { target: false },
|
||||
}),
|
||||
)
|
||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
||||
options: QueryPostDto,
|
||||
) {
|
||||
return this.postService.paginate(options);
|
||||
@ -50,11 +44,7 @@ export class PostController {
|
||||
async store(
|
||||
@Body(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidUnknownValues: true,
|
||||
forbidNonWhitelisted: true,
|
||||
validationError: { target: false },
|
||||
...DEFAULT_VALIDATION_CONFIG,
|
||||
groups: ['create'],
|
||||
}),
|
||||
)
|
||||
@ -68,11 +58,7 @@ export class PostController {
|
||||
async update(
|
||||
@Body(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidUnknownValues: true,
|
||||
forbidNonWhitelisted: true,
|
||||
validationError: { target: false },
|
||||
...DEFAULT_VALIDATION_CONFIG,
|
||||
groups: ['update'],
|
||||
}),
|
||||
)
|
||||
|
65
src/modules/content/controllers/tag.controller.ts
Normal file
65
src/modules/content/controllers/tag.controller.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
SerializeOptions,
|
||||
UseInterceptors,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
|
||||
import { AppInterceptor } from '@/modules/core/providers/app.interceptor';
|
||||
|
||||
import { DEFAULT_VALIDATION_CONFIG } from '../constants';
|
||||
import { CreateTagDto, QueryTagDto, UpdateTagDto } from '../dtos/tag.dto';
|
||||
import { TagService } from '../services';
|
||||
|
||||
@Controller('tag')
|
||||
@UseInterceptors(AppInterceptor)
|
||||
export class TagController {
|
||||
constructor(protected service: TagService) {}
|
||||
|
||||
@Get()
|
||||
@SerializeOptions({})
|
||||
async list(
|
||||
@Query(new ValidationPipe(DEFAULT_VALIDATION_CONFIG))
|
||||
options: QueryTagDto,
|
||||
) {
|
||||
return this.service.paginate(options);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@SerializeOptions({})
|
||||
async detail(@Param('id', new ParseUUIDPipe()) id: string) {
|
||||
return this.service.detail(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@SerializeOptions({})
|
||||
async store(
|
||||
@Body(new ValidationPipe({ ...DEFAULT_VALIDATION_CONFIG, groups: ['create'] }))
|
||||
data: CreateTagDto,
|
||||
) {
|
||||
return this.service.create(data);
|
||||
}
|
||||
|
||||
@Patch()
|
||||
@SerializeOptions({})
|
||||
async update(
|
||||
@Body(new ValidationPipe({ ...DEFAULT_VALIDATION_CONFIG, groups: ['update'] }))
|
||||
date: UpdateTagDto,
|
||||
) {
|
||||
return this.service.update(date);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@SerializeOptions({})
|
||||
async delete(@Param('id', new ParseUUIDPipe()) id: string) {
|
||||
return this.service.delete(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user