import { Body, Controller, Del, Get, Inject, Param, Post, Query, } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { CollectionService } from '../service/Collection.service'; import { CDTO_Collection, CVO_Collection, FVO_Collection, QDTO_Collection, QVO_Collection, UDTO_Collection, UVAO_Collection, } from '../interface/Collection.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['回款审批设置']) @Controller('/Collection') export class CollectionController extends BaseController { @Inject() service: CollectionService; @Post('/') @Validate() @ApiResponse({ type: CVO_Collection }) async create(@Body() data: CDTO_Collection) { const dbData = await this.service.create(data); const result = new CVO_Collection(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_Collection }) async query( @Query() filter: QDTO_Collection, @Query('skip') skip: number, @Query('limit') limit: number ) { const list = await this.service.query(filter, { skip, limit }); const data = []; for (const i of list) { const newData = new QVO_Collection(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_Collection }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_Collection(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_Collection }) async update(@Param('id') id: string, @Body() body: UDTO_Collection) { const result = await this.service.updateOne(id, body); return result; } @Del('/:id') @Validate() async delete(@Param('id') id: string) { await this.service.delete(id); return 'ok'; } async createMany(...args: any[]) { throw new Error('Method not implemented.'); } async updateMany(...args: any[]) { throw new Error('Method not implemented.'); } async deleteMany(...args: any[]) { throw new Error('Method not implemented.'); } }