|
@@ -10,7 +10,6 @@ const getModelType = (type, interf = false) => {
|
|
return modelType;
|
|
return modelType;
|
|
};
|
|
};
|
|
const ModelContext = (data) => {
|
|
const ModelContext = (data) => {
|
|
- const result = [];
|
|
|
|
const { name: table_name, columns } = data;
|
|
const { name: table_name, columns } = data;
|
|
const prefix = _.upperFirst(table_name);
|
|
const prefix = _.upperFirst(table_name);
|
|
let fc = [];
|
|
let fc = [];
|
|
@@ -25,7 +24,7 @@ const ModelContext = (data) => {
|
|
// 处理字段
|
|
// 处理字段
|
|
for (const col of columns) {
|
|
for (const col of columns) {
|
|
const { type, title, def } = col;
|
|
const { type, title, def } = col;
|
|
- const prop = _.pick(col, ['required', 'index', 'zh', 'remark']);
|
|
|
|
|
|
+ const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark']);
|
|
if (def) prop.default = def;
|
|
if (def) prop.default = def;
|
|
const modelType = getModelType(type);
|
|
const modelType = getModelType(type);
|
|
fc.push(` @prop(${JSON.stringify(prop)})`);
|
|
fc.push(` @prop(${JSON.stringify(prop)})`);
|
|
@@ -79,8 +78,8 @@ const ControllerContext = (data) => {
|
|
fc.push(` return result;`);
|
|
fc.push(` return result;`);
|
|
fc.push(` }`);
|
|
fc.push(` }`);
|
|
// query
|
|
// query
|
|
- 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(`@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(` 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 };`);
|
|
@@ -160,18 +159,23 @@ const interfaceContext = (data) => {
|
|
fc.push(` this[key] = _.get(data, key);`);
|
|
fc.push(` this[key] = _.get(data, key);`);
|
|
fc.push(` }`);
|
|
fc.push(` }`);
|
|
fc.push(` }`);
|
|
fc.push(` }`);
|
|
|
|
+ fc.push(` @ApiProperty({ description: '数据id' })`);
|
|
|
|
+ fc.push(` _id: string = undefined;`);
|
|
for (const col of columns) {
|
|
for (const col of columns) {
|
|
const cfc = getInterfaceColumn(col);
|
|
const cfc = getInterfaceColumn(col);
|
|
fc.push(...cfc);
|
|
fc.push(...cfc);
|
|
}
|
|
}
|
|
fc.push(`}`);
|
|
fc.push(`}`);
|
|
fc.push(`\n`);
|
|
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 class QueryDTO_${name} extends SearchBase {`);
|
|
fc.push(` constructor() {`);
|
|
fc.push(` constructor() {`);
|
|
fc.push(` const like_prop = [];`);
|
|
fc.push(` const like_prop = [];`);
|
|
|
|
+ fc.push(` const props = [${props}];`);
|
|
fc.push(` super({ like_prop });`);
|
|
fc.push(` super({ like_prop });`);
|
|
fc.push(` }`);
|
|
fc.push(` }`);
|
|
- for (const col of columns.filter((f) => f.index)) {
|
|
|
|
|
|
+ for (const col of indexs) {
|
|
const cfc = getInterfaceColumn(col);
|
|
const cfc = getInterfaceColumn(col);
|
|
fc.push(...cfc);
|
|
fc.push(...cfc);
|
|
}
|
|
}
|
|
@@ -188,7 +192,11 @@ const interfaceContext = (data) => {
|
|
fc.push(`\n`);
|
|
fc.push(`\n`);
|
|
fc.push(`export class CreateVO_${name} extends FetchVO_${name} {}`);
|
|
fc.push(`export class CreateVO_${name} extends FetchVO_${name} {}`);
|
|
fc.push(`\n`);
|
|
fc.push(`\n`);
|
|
- fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {}`);
|
|
|
|
|
|
+ fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {
|
|
|
|
+ @ApiProperty({ description: '数据id' })
|
|
|
|
+ @Rule(RuleType['string']().empty())
|
|
|
|
+ _id: string = undefined;
|
|
|
|
+}`);
|
|
fc.push(`\n`);
|
|
fc.push(`\n`);
|
|
fc.push(`export class UpdateVO_${name} extends FetchVO_${name} {}`);
|
|
fc.push(`export class UpdateVO_${name} extends FetchVO_${name} {}`);
|
|
return fc.join('\n');
|
|
return fc.join('\n');
|