import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { IncubatorService } from '../../service/users/incubator.service'; import { CDTO_incubator, CVO_incubator, FVO_incubator, QDTO_incubator, QVO_incubator, UDTO_incubator, UVAO_incubator } from '../../interface/users/incubator.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['孵化器']) @Controller('/incubator') export class IncubatorController extends BaseController { @Inject() service: IncubatorService; @Post('/') @Validate() @ApiResponse({ type: CVO_incubator }) async create(@Body() data: CDTO_incubator) { const dbData = await this.service.create(data); const result = new CVO_incubator(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_incubator }) async query(@Query() filter: QDTO_incubator, @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_incubator(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_incubator }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_incubator(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_incubator }) async update(@Param('id') id: string, @Body() body: UDTO_incubator) { 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.'); } }