lrf 2 éve
szülő
commit
42eb3526c3
1 módosított fájl, 19 hozzáadás és 17 törlés
  1. 19 17
      app/public/ts-template.js

+ 19 - 17
app/public/ts-template.js

@@ -58,7 +58,9 @@ const ControllerContext = (data) => {
   fc.push(`import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';`);
   fc.push(`import { BaseController } from 'free-midway-component';`);
   fc.push(`import { ${prefix}Service } from '../service/${table_name}.service';`);
-  fc.push(`import { CreateDTO, CreateVO, FetchVO, QueryDTO, QueryVO, UpdateDTO, UpdateVO } from '../interface/${table_name}.interface';`);
+  fc.push(
+    `import { Create_${table_name}DTO, Create_${table_name}VO, Fetch_${table_name}VO, Query_${table_name}DTO, Query_${table_name}VO, Update_${table_name}DTO, Update_${table_name}VO } from '../interface/${table_name}.interface';`
+  );
   fc.push(`import { ApiResponse, ApiTags } from '@midwayjs/swagger';`);
   fc.push(`import { Validate } from '@midwayjs/validate';`);
   fc.push(`@ApiTags(['${name_zh}'])`);
@@ -68,30 +70,30 @@ const ControllerContext = (data) => {
   fc.push(`  service: ${prefix}Service;`);
   fc.push('\n');
   // create
-  fc.push(`@Post('/') @Validate() @ApiResponse({ type: CreateVO })`);
-  fc.push(`  async create(@Body() data: CreateDTO) {`);
+  fc.push(`@Post('/') @Validate() @ApiResponse({ type: Create_${table_name}VO })`);
+  fc.push(`  async create(@Body() data: Create_${table_name}DTO) {`);
   fc.push(`    const result = await this.service.create(data);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
   // query
-  fc.push(`@Get('/')@ApiResponse({ type: QueryVO })`);
-  fc.push(`  async query(@Query('filter') filter: QueryDTO, @Query('skip') skip: number,@Query('limit') limit: number){`);
+  fc.push(`@Get('/')@ApiResponse({ type: Query_${table_name}VO })`);
+  fc.push(`  async query(@Query('filter') filter: Query_${table_name}DTO, @Query('skip') skip: number,@Query('limit') limit: number){`);
   fc.push(`    const data = await this.service.query(filter, { skip, limit });`);
   fc.push(`    const total = await this.service.count(filter);`);
   fc.push(`    return { data, total };`);
   fc.push(`  }`);
   fc.push(`\n`);
   // fetch
-  fc.push(`@Get('/:id')@ApiResponse({ type: FetchVO })`);
+  fc.push(`@Get('/:id')@ApiResponse({ type: Fetch_${table_name}VO })`);
   fc.push(`  async fetch(@Param('id') id: string) {`);
   fc.push(`    const data = await this.service.fetch(id);`);
-  fc.push(`    const result = new FetchVO(data);`);
+  fc.push(`    const result = new Fetch_${table_name}VO(data);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
   fc.push(`\n`);
   // update
-  fc.push(`@Post('/:id')@Validate()@ApiResponse({ type: UpdateVO })`);
-  fc.push(`  async update(@Param('id') id: string, @Body() body: UpdateDTO) {`);
+  fc.push(`@Post('/:id')@Validate()@ApiResponse({ type: Update_${table_name}VO })`);
+  fc.push(`  async update(@Param('id') id: string, @Body() body: Update_${table_name}DTO) {`);
   fc.push(`    const result = await this.service.updateOne(id, body);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
@@ -139,12 +141,12 @@ const getInterfaceColumn = (col, needReq = false) => {
 
 const interfaceContext = (data) => {
   const fc = [];
-  const { columns = [] } = data;
+  const { columns = [],name } = data;
   fc.push(`import { Rule, RuleType } from '@midwayjs/validate';`);
   fc.push(`import { ApiProperty } from '@midwayjs/swagger';`);
   fc.push(`import _ = require('lodash');`);
   fc.push(`import { FrameworkErrorEnum, SearchBase, ServiceError } from 'free-midway-component';`);
-  fc.push(`export class FetchVO {`);
+  fc.push(`export class FetchVO_${name} {`);
   fc.push(`  constructor(data: object) {`);
   fc.push(`    for (const key of Object.keys(this)) {`);
   fc.push(`      this[key] = _.get(data, key);`);
@@ -156,7 +158,7 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class QueryDTO extends SearchBase {`);
+  fc.push(`export class Query_${name}DTO extends SearchBase {`);
   fc.push(`  constructor() {`);
   fc.push(`    const like_prop = [];`);
   fc.push(`    super({ like_prop });`);
@@ -167,20 +169,20 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class QueryVO extends FetchVO {}`);
+  fc.push(`export class Query_${name}VO extends FetchVO {}`);
   fc.push(`\n`);
-  fc.push(`export class CreateDTO {`);
+  fc.push(`export class Create_${name}DTO {`);
   for (const col of columns) {
     const cfc = getInterfaceColumn(col, true);
     fc.push(...cfc);
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class CreateVO extends FetchVO {}`);
+  fc.push(`export class Create_${name}VO extends Fetch_${name}VO {}`);
   fc.push(`\n`);
-  fc.push(`export class UpdateDTO extends CreateDTO {}`);
+  fc.push(`export class Update_${name}DTO extends Create_${name}DTO {}`);
   fc.push(`\n`);
-  fc.push(`export class UpdateVO extends FetchVO {}`);
+  fc.push(`export class Update_${name}VO extends Fetch_${name}VO {}`);
   return fc.join('\n');
 };