浏览代码

ts template

lrf 2 年之前
父节点
当前提交
7415d8a97a
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      app/public/ts-template.js

+ 4 - 2
app/public/ts-template.js

@@ -132,8 +132,10 @@ const getInterfaceColumn = (col, needReq = false) => {
   const { type, zh, title, required } = col;
   const { type, zh, title, required } = col;
   const modelType = getModelType(type);
   const modelType = getModelType(type);
   fc.push(`  @ApiProperty({ description: '${title}' })`);
   fc.push(`  @ApiProperty({ description: '${title}' })`);
-  if (needReq && required) {
-    const ruleStr = `@Rule(RuleType['${modelType}']().required().error(new ServiceError('缺少${zh}',FrameworkErrorEnum.${needReq ? 'NEED_BODY' : 'NEED_QUERY'})))`;
+  if (needReq) {
+    let ruleStr = '';
+    if (required) ruleStr = `@Rule(RuleType['${modelType}']().required().error(new ServiceError('缺少${zh}',FrameworkErrorEnum.${needReq ? 'NEED_BODY' : 'NEED_QUERY'})))`;
+    else ruleStr = `@Rule(RuleType['${modelType}'].empty())`;
     fc.push(ruleStr);
     fc.push(ruleStr);
   }
   }
   fc.push(`  '${title}': ${modelType} = undefined;`);
   fc.push(`  '${title}': ${modelType} = undefined;`);