import { Body, Controller, Del, Get, Inject, Param, Post, Query, } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { GoodService } from '../service/Good.service'; import { CDTO_Good, CVO_Good, FVO_Good, QDTO_Good, QVO_Good, UDTO_Good, UVAO_Good, } from '../interface/Good.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['商品']) @Controller('/Good') export class GoodController extends BaseController { @Inject() service: GoodService; @Post('/') @Validate() @ApiResponse({ type: CVO_Good }) async create(@Body() data: CDTO_Good) { const dbData = await this.service.create(data); const result = new CVO_Good(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_Good }) async query( @Query() filter: QDTO_Good, @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_Good(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_Good }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_Good(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_Good }) async update(@Param('id') id: string, @Body() body: UDTO_Good) { 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.'); } }