Jelajahi Sumber

ts template

lrf 2 tahun lalu
induk
melakukan
10da206a07
1 mengubah file dengan 15 tambahan dan 15 penghapusan
  1. 15 15
      app/public/ts-template.js

+ 15 - 15
app/public/ts-template.js

@@ -59,7 +59,7 @@ const ControllerContext = (data) => {
   fc.push(`import { BaseController } from 'free-midway-component';`);
   fc.push(`import { ${prefix}Service } from '../service/${table_name}.service';`);
   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';`
+    `import { CreateDTO_${name}, CreateVO_${name}, FetchVO_${name}, QueryDTO_${name}, QueryVO_${name}, UpdateDTO_${name}, UpdateVO_${name} } from '../interface/${table_name}.interface';`
   );
   fc.push(`import { ApiResponse, ApiTags } from '@midwayjs/swagger';`);
   fc.push(`import { Validate } from '@midwayjs/validate';`);
@@ -70,30 +70,30 @@ const ControllerContext = (data) => {
   fc.push(`  service: ${prefix}Service;`);
   fc.push('\n');
   // create
-  fc.push(`@Post('/') @Validate() @ApiResponse({ type: Create_${table_name}VO })`);
-  fc.push(`  async create(@Body() data: Create_${table_name}DTO) {`);
+  fc.push(`@Post('/') @Validate() @ApiResponse({ type: CreateVO_${name} })`);
+  fc.push(`  async create(@Body() data: CreateDTO_${name}) {`);
   fc.push(`    const result = await this.service.create(data);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
   // query
-  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(`@Get('/')@ApiResponse({ type: QueryVO_${name} })`);
+  fc.push(`  async query(@Query('filter') filter: QueryDTO_${name}, @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: Fetch_${table_name}VO })`);
+  fc.push(`@Get('/:id')@ApiResponse({ type: FetchVO_${name} })`);
   fc.push(`  async fetch(@Param('id') id: string) {`);
   fc.push(`    const data = await this.service.fetch(id);`);
-  fc.push(`    const result = new Fetch_${table_name}VO(data);`);
+  fc.push(`    const result = new FetchVO_${name}(data);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
   fc.push(`\n`);
   // update
-  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(`@Post('/:id')@Validate()@ApiResponse({ type: UpdateVO_${name} })`);
+  fc.push(`  async update(@Param('id') id: string, @Body() body: UpdateDTO_${name}) {`);
   fc.push(`    const result = await this.service.updateOne(id, body);`);
   fc.push(`    return result;`);
   fc.push(`  }`);
@@ -158,7 +158,7 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class Query_${name}DTO extends SearchBase {`);
+  fc.push(`export class QueryDTO extends SearchBase {`);
   fc.push(`  constructor() {`);
   fc.push(`    const like_prop = [];`);
   fc.push(`    super({ like_prop });`);
@@ -169,20 +169,20 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class Query_${name}VO extends FetchVO {}`);
+  fc.push(`export class QueryVO_${name} extends FetchVO_${name} {}`);
   fc.push(`\n`);
-  fc.push(`export class Create_${name}DTO {`);
+  fc.push(`export class CreateDTO_${name} {`);
   for (const col of columns) {
     const cfc = getInterfaceColumn(col, true);
     fc.push(...cfc);
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class Create_${name}VO extends Fetch_${name}VO {}`);
+  fc.push(`export class CreateVO_${name} extends FetchVO_${name} {}`);
   fc.push(`\n`);
-  fc.push(`export class Update_${name}DTO extends Create_${name}DTO {}`);
+  fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {}`);
   fc.push(`\n`);
-  fc.push(`export class Update_${name}VO extends Fetch_${name}VO {}`);
+  fc.push(`export class UpdateVO_${name} extends FetchVO_${name} {}`);
   return fc.join('\n');
 };