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