import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { NegotiateService } from '../../../service/core/trade/negotiate.service'; import { CDTO_negotiate, CVO_negotiate, FVO_negotiate, QDTO_negotiate, QVO_negotiate, UDTO_negotiate, UVAO_negotiate } from '../../../interface/core/trade/negotiate.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['协商定价']) @Controller('/negotiate') export class NegotiateController extends BaseController { @Inject() service: NegotiateService; @Post('/') @Validate() @ApiResponse({ type: CVO_negotiate }) async create(@Body() data: CDTO_negotiate) { const dbData = await this.service.create(data); const result = new CVO_negotiate(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_negotiate }) async query(@Query() filter: QDTO_negotiate, @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_negotiate(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_negotiate }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_negotiate(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_negotiate }) async update(@Param('id') id: string, @Body() body: UDTO_negotiate) { 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.'); } }