import { Body, Controller, Del, Get, Inject, Param, Post, Query, } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { UpkeepService } from '../service/Upkeep.service'; import { CDTO_upkeep, CVO_upkeep, FVO_upkeep, QDTO_upkeep, QVO_upkeep, UDTO_upkeep, UVAO_upkeep, } from '../interface/Upkeep.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; import { UserUtilService } from '../service/util/user.util'; @ApiTags(['维修表']) @Controller('/Upkeep') export class UpkeepController extends BaseController { @Inject() service: UpkeepService; @Inject() userUtil: UserUtilService; @Post('/') @Validate() @ApiResponse({ type: CVO_upkeep }) async create(@Body() data: CDTO_upkeep) { // 检查是否创建相同维修数据 await this.userUtil.checkUpkeep(data); await this.service.createBefore(data); const dbData = await this.service.create(data); const result = new CVO_upkeep(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_upkeep }) async query( @Query() filter: QDTO_upkeep, @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_upkeep(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_upkeep }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_upkeep(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_upkeep }) async update(@Param('id') id: string, @Body() body: UDTO_upkeep) { const result = await this.service.update(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.'); } }