q-koa 11.3.3 → 11.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/app.js CHANGED
@@ -853,6 +853,7 @@ class APP {
853
853
  !_.get(app, `${appName}.model.${controller}`) ||
854
854
  !_.get(app, `${appName}.controller.${controller}`)
855
855
  ) {
856
+ console.error(`${controller}`)
856
857
  throw new Error('路由model定义缺失')
857
858
  }
858
859
  await next()
@@ -870,6 +871,7 @@ class APP {
870
871
  !_.get(app, `${appName}.model.${controller}.${fn}`) &&
871
872
  !_.get(app, `${appName}.controller.${controller}.${fn}`)
872
873
  ) {
874
+ console.error(`${controller}.${fn}`)
873
875
  throw new Error('路由fn定义缺失')
874
876
  }
875
877
 
@@ -22,7 +22,11 @@ exports.initModel = async (ctx) => {
22
22
  alter: true,
23
23
  }
24
24
 
25
+ const appConfig = getConfig(app)
25
26
  if (Array.isArray(model)) {
27
+ const { is_dev } = await appConfig.getObject('base')
28
+ if (!is_dev && option === 'force')
29
+ throw new Error('正式环境不允许array model force')
26
30
  await Promise.all(model.map((m) => app.model[m].sync(config)))
27
31
  return ctx.SUCCESS('ok')
28
32
  }
@@ -180,7 +184,7 @@ exports.showTables = async (ctx) => {
180
184
  autoData: lodash.get(target, 'autoData', null),
181
185
  // 有些model需要前置查询其它model数据
182
186
  initList: lodash.get(target, 'initList', []),
183
- // 有些model的table需要前置查询模型
187
+ // 有些table需要前置查询数据
184
188
  initTableList: lodash.get(target, 'initTableList', []),
185
189
  // 局部更新列表
186
190
  editInline: lodash.get(target, 'editInline', {}),
@@ -188,9 +192,9 @@ exports.showTables = async (ctx) => {
188
192
  comment: lodash.get(target, 'comment', {}),
189
193
  // 默认查询,覆盖之前
190
194
  modelQuery: lodash.get(target, 'modelQuery', {}),
191
- // 插入字段,覆盖之前
195
+ // 默认更新,覆盖之前
192
196
  modelUpsert: lodash.get(target, 'modelUpsert', {}),
193
- // 编辑软删除
197
+ // 软删除比如is_on:false,就upsert
194
198
  modelDelete: lodash.get(target, 'modelDelete', {}),
195
199
  // 删除时检查是不是含有
196
200
  deleteCheckList: lodash.get(target, 'deleteCheckList', []),
@@ -3,9 +3,12 @@ const { Validator, getAppByCtx } = require('q-koa')
3
3
  exports.initModel = async (ctx) => {
4
4
  const params = {
5
5
  model: {
6
- type: 'string',
7
6
  required: true,
8
7
  message: '请输入model',
8
+ validator: (rule, value) =>
9
+ typeof value === 'string' || Array.isArray(value)
10
+ ? Promise.resolve()
11
+ : Promise.reject(new Error('string | array')),
9
12
  },
10
13
  }
11
14
  await new Validator(params).validate(ctx.request.body)
@@ -22,7 +25,7 @@ exports.showAllSchemas = async (ctx) => {
22
25
  validator: (rule, value) =>
23
26
  app[appName].model && app[appName].model[value]
24
27
  ? Promise.resolve()
25
- : Promise.reject('没有这个模型'),
28
+ : Promise.reject(new Error('没有这个模型')),
26
29
  },
27
30
  }
28
31
  await new Validator(params).validate(ctx.request.body)
@@ -39,7 +42,7 @@ exports.dropModel = async (ctx) => {
39
42
  validator: (rule, value) =>
40
43
  app[appName].model && app[appName].model[value]
41
44
  ? Promise.resolve()
42
- : Promise.reject('没有这个模型'),
45
+ : Promise.reject(new Error('没有这个模型')),
43
46
  },
44
47
  }
45
48
  await new Validator(params).validate(ctx.request.body)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "11.3.3",
3
+ "version": "11.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {