monorepo/apps/api/src/modules/content/controllers/post.controller.ts

70 lines
1.6 KiB
TypeScript

import {
Body,
Controller,
Get,
Param,
ParseUUIDPipe,
Patch,
Post,
Query,
SerializeOptions,
} from '@nestjs/common';
import { DeleteWithTrashDto, RestoreDto } from '@/modules/restful/delete-with-trash.dto';
import { QueryPostDto, UpdatePostDto } from '../dtos/post.dto';
import { PostService } from '../services/post.service';
@Controller('posts')
export class PostController {
constructor(protected postservice: PostService) {}
@Get()
@SerializeOptions({ groups: ['post-list'] })
async list(
@Query()
options: QueryPostDto,
) {
return this.postservice.paginate(options);
}
@Get(':id')
@SerializeOptions({ groups: ['post-detail'] })
async detail(
@Param('id', new ParseUUIDPipe())
id: string,
) {
return this.postservice.detail(id);
}
@Post()
@SerializeOptions({ groups: ['post-detail'] })
async store(
@Body()
data: any,
) {
return this.postservice.create(data);
}
@Patch()
@SerializeOptions({ groups: ['post-detail'] })
async update(
@Body()
data: UpdatePostDto,
) {
return this.postservice.update(data);
}
@Post('delete')
@SerializeOptions({ groups: ['post-list'] })
async delete(@Body() data: DeleteWithTrashDto) {
return this.postservice.delete(data.ids, data.transh);
}
@Post('restore')
@SerializeOptions({ groups: ['post-list'] })
async restore(@Body() data: RestoreDto) {
return this.postservice.restore(data.ids);
}
}