|
@@ -61,7 +61,7 @@ const ControllerContext = (data) => {
|
|
|
fc.push(`import { BaseController } from 'free-midway-component';`);
|
|
|
fc.push(`import { ${prefix}Service } from '../service/${name}.service';`);
|
|
|
fc.push(
|
|
|
- `import { CreateDTO_${name}, CreateVO_${name}, FetchVO_${name}, QueryDTO_${name}, QueryVO_${name}, UpdateDTO_${name}, UpdateVO_${name} } from '../interface/${name}.interface';`
|
|
|
+ `import { CDTO, CVO, FVO,QDTO, QVO, UDTO, UVAO } from '../interface/${name}.interface';`
|
|
|
);
|
|
|
fc.push(`import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';`);
|
|
|
fc.push(`import { Validate } from '@midwayjs/validate';`);
|
|
@@ -72,30 +72,30 @@ const ControllerContext = (data) => {
|
|
|
fc.push(` service: ${prefix}Service;`);
|
|
|
fc.push('\n');
|
|
|
// create
|
|
|
- fc.push(`@Post('/') @Validate() @ApiResponse({ type: CreateVO_${name} })`);
|
|
|
- fc.push(` async create(@Body() data: CreateDTO_${name}) {`);
|
|
|
+ fc.push(`@Post('/') @Validate() @ApiResponse({ type: CVO })`);
|
|
|
+ fc.push(` async create(@Body() data: CDTO) {`);
|
|
|
fc.push(` const result = await this.service.create(data);`);
|
|
|
fc.push(` return result;`);
|
|
|
fc.push(` }`);
|
|
|
// query
|
|
|
- fc.push(`@Get('/')@ApiQuery({name:'query'})@ApiResponse({ type: QueryVO_${name} })`);
|
|
|
- fc.push(` async query(@Query() filter: QueryDTO_${name}, @Query('skip') skip: number,@Query('limit') limit: number){`);
|
|
|
+ fc.push(`@Get('/')@ApiQuery({name:'query'})@ApiResponse({ type: QVO })`);
|
|
|
+ fc.push(` async query(@Query() filter:QDTO, @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_${name} })`);
|
|
|
+ fc.push(`@Get('/:id')@ApiResponse({ type: FVO })`);
|
|
|
fc.push(` async fetch(@Param('id') id: string) {`);
|
|
|
fc.push(` const data = await this.service.fetch(id);`);
|
|
|
- fc.push(` const result = new FetchVO_${name}(data);`);
|
|
|
+ fc.push(` const result = new FVO(data);`);
|
|
|
fc.push(` return result;`);
|
|
|
fc.push(` }`);
|
|
|
fc.push(`\n`);
|
|
|
// update
|
|
|
- fc.push(`@Post('/:id')@Validate()@ApiResponse({ type: UpdateVO_${name} })`);
|
|
|
- fc.push(` async update(@Param('id') id: string, @Body() body: UpdateDTO_${name}) {`);
|
|
|
+ fc.push(`@Post('/:id')@Validate()@ApiResponse({ type: UVAO })`);
|
|
|
+ fc.push(` async update(@Param('id') id: string, @Body() body: UDTO) {`);
|
|
|
fc.push(` const result = await this.service.updateOne(id, body);`);
|
|
|
fc.push(` return result;`);
|
|
|
fc.push(` }`);
|
|
@@ -155,7 +155,7 @@ const interfaceContext = (data) => {
|
|
|
fc.push(`import _ = require('lodash');`);
|
|
|
if (have_required) fc.push(`import { FrameworkErrorEnum, SearchBase, ServiceError } from 'free-midway-component';`);
|
|
|
else fc.push(`import { SearchBase } from 'free-midway-component';`);
|
|
|
- fc.push(`export class FetchVO_${name} {`);
|
|
|
+ fc.push(`export class FVO {`);
|
|
|
fc.push(` constructor(data: object) {`);
|
|
|
fc.push(` for (const key of Object.keys(this)) {`);
|
|
|
fc.push(` this[key] = _.get(data, key);`);
|
|
@@ -171,7 +171,7 @@ const interfaceContext = (data) => {
|
|
|
fc.push(`\n`);
|
|
|
const indexs = columns.filter((f) => f.index);
|
|
|
const props = indexs.map((i) => `'${i.title}'`).join(', ');
|
|
|
- fc.push(`export class QueryDTO_${name} extends SearchBase {`);
|
|
|
+ fc.push(`export classQDTO extends SearchBase {`);
|
|
|
fc.push(` constructor() {`);
|
|
|
fc.push(` const like_prop = [];`);
|
|
|
fc.push(` const props = [${props}];`);
|
|
@@ -184,24 +184,24 @@ const interfaceContext = (data) => {
|
|
|
}
|
|
|
fc.push(`}`);
|
|
|
fc.push(`\n`);
|
|
|
- fc.push(`export class QueryVO_${name} extends FetchVO_${name} {}`);
|
|
|
+ fc.push(`export class QVO extends FVO {}`);
|
|
|
fc.push(`\n`);
|
|
|
- fc.push(`export class CreateDTO_${name} {`);
|
|
|
+ fc.push(`export class CDTO {`);
|
|
|
for (const col of columns) {
|
|
|
const cfc = getInterfaceColumn(col, true);
|
|
|
fc.push(...cfc);
|
|
|
}
|
|
|
fc.push(`}`);
|
|
|
fc.push(`\n`);
|
|
|
- fc.push(`export class CreateVO_${name} extends FetchVO_${name} {}`);
|
|
|
+ fc.push(`export class CVO extends FVO {}`);
|
|
|
fc.push(`\n`);
|
|
|
- fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {
|
|
|
+ fc.push(`export class UDTO extends CDTO {
|
|
|
@ApiProperty({ description: '数据id' })
|
|
|
@Rule(RuleType['string']().empty(''))
|
|
|
_id: string = undefined;
|
|
|
}`);
|
|
|
fc.push(`\n`);
|
|
|
- fc.push(`export class UpdateVO_${name} extends FetchVO_${name} {}`);
|
|
|
+ fc.push(`export class UVAO extends FVO {}`);
|
|
|
return fc.join('\n');
|
|
|
};
|
|
|
|