q-koa 13.0.0 → 13.0.2

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
@@ -22,7 +22,7 @@ const jwt = require('jsonwebtoken')
22
22
  const verify = util.promisify(jwt.verify)
23
23
  const fsExtra = require('fs-extra')
24
24
  const { getObject, getAppConfig } = require('./file/utils')
25
- const { push } = require('./file/plugins/log/service')
25
+
26
26
  const restc = require('./restc')
27
27
  const APP_DIR = 'app'
28
28
  const PLUGINS_DIR = 'plugins'
@@ -472,6 +472,8 @@ class APP {
472
472
  await this.initModel(appName)
473
473
  // const models = Object.keys(this.app[appName].model).join(' / ')
474
474
  } catch (e) {
475
+ const { push } = require('./file/plugins/log/service')
476
+
475
477
  push({
476
478
  appName,
477
479
  message: `${appName}数据库连接失败`,
@@ -773,7 +775,7 @@ class APP {
773
775
  }
774
776
  }
775
777
  const start = moment().valueOf()
776
- for (const fn of ['service', 'controller']) {
778
+ for (const fn of ['service']) {
777
779
  const cloneTarget = this.app[appName][fn]
778
780
 
779
781
  this.app[appName][fn] = Object.keys(cloneTarget).reduce((a, b) => {
@@ -1152,64 +1154,57 @@ class APP {
1152
1154
 
1153
1155
  if (where) {
1154
1156
  if (fn === 'findAndCountAll') {
1155
- const formatWhere = _.mapValues(where, (item) => {
1156
- if (_.isObject(item)) {
1157
- if (
1158
- item.hasOwnProperty('$notIn') &&
1159
- typeof item.$notIn === 'string'
1160
- ) {
1161
- return {
1162
- $notIn: [Sequelize.literal(item.$notIn)],
1163
- }
1157
+ const $lt = {
1158
+ check: (param) => typeof param === 'string',
1159
+ result: (param, key) => {
1160
+ return {
1161
+ [key]: Sequelize.literal(param[key]),
1164
1162
  }
1165
-
1166
- if (
1167
- item.hasOwnProperty('$in') &&
1168
- typeof item.$in === 'string'
1169
- ) {
1170
- return {
1171
- $in: [Sequelize.literal(item.$in)],
1172
- }
1173
- }
1174
- if (
1175
- item.hasOwnProperty('$lt') &&
1176
- typeof item.$lt === 'string'
1177
- ) {
1178
- return {
1179
- $lt: Sequelize.literal(item.$lt),
1180
- }
1181
- }
1182
-
1183
- if (
1184
- item.hasOwnProperty('$lte') &&
1185
- typeof item.$lte === 'string'
1186
- ) {
1187
- return {
1188
- $lte: Sequelize.literal(item.$lte),
1189
- }
1163
+ },
1164
+ }
1165
+ const $in = {
1166
+ check: (param) => typeof param === 'string',
1167
+ result: (param, key) => {
1168
+ return {
1169
+ [key]: [Sequelize.literal(param[key])],
1190
1170
  }
1191
-
1192
- if (
1193
- item.hasOwnProperty('$gt') &&
1194
- typeof item.$gt === 'string'
1195
- ) {
1196
- return {
1197
- $gt: Sequelize.literal(item.$gt),
1198
- }
1171
+ },
1172
+ }
1173
+ const $between = {
1174
+ check: (param) => Array.isArray(param),
1175
+ result: (param, key) => {
1176
+ return {
1177
+ [key]: param[key].map(Sequelize.literal),
1199
1178
  }
1200
-
1201
- if (
1202
- item.hasOwnProperty('$gte') &&
1203
- typeof item.$gte === 'string'
1204
- ) {
1205
- return {
1206
- $gte: Sequelize.literal(item.$gte),
1179
+ },
1180
+ }
1181
+ const mapper = {
1182
+ $between,
1183
+ notBetween: $between,
1184
+ $lt,
1185
+ $lte: $lt,
1186
+ $gt: $lt,
1187
+ $gte: $lt,
1188
+ $in,
1189
+ $notIn: $in,
1190
+ }
1191
+ const formatObj = (target) => {
1192
+ for (const key of Object.keys(mapper)) {
1193
+ if (Object.hasOwnProperty.call(target, key)) {
1194
+ if (mapper[key].check(target[key])) {
1195
+ return mapper[key].result(target, key)
1196
+ } else {
1197
+ return target
1207
1198
  }
1199
+ } else {
1200
+ continue
1208
1201
  }
1209
- return item
1210
- } else {
1211
- return item
1212
1202
  }
1203
+ return target
1204
+ }
1205
+ const formatWhere = _.mapValues(where, (item) => {
1206
+ if (!_.isObject(item)) return item
1207
+ return formatObj(item)
1213
1208
  })
1214
1209
  _where = _.cloneDeep(formatWhere)
1215
1210
  } else {
@@ -413,11 +413,9 @@ exports.initDataWithCache = exports.initData = async (ctx) => {
413
413
 
414
414
  const { is_cache } = await appConfig.getObject('base')
415
415
  const { includes, excludes = [] } = ctx.request.body
416
-
417
416
  if (!includes) {
418
417
  return ctx.SUCCESS(null)
419
418
  }
420
-
421
419
  const cacheTarget = JSON.stringify(ctx.request.body)
422
420
 
423
421
  let result = null
@@ -150,19 +150,29 @@ exports.login = async (ctx) => {
150
150
  ].filter((item) => item.model)
151
151
  : []
152
152
  if (app.appConfig.loginData) {
153
+ const application = await getAppConfig({ app, config })
154
+
155
+ const loginData = lodash.mergeWith(
156
+ app.appConfig.loginData,
157
+ lodash.get(application, 'loginData', {}),
158
+ (objValue, srcValue) => {
159
+ if (lodash.isArray(objValue)) {
160
+ return objValue.concat(srcValue)
161
+ }
162
+ }
163
+ )
153
164
  const include = includeDefault.filter((i) => {
154
- return app.appConfig.loginData.excludeInclude.every((m) => {
165
+ return loginData.excludeInclude.every((m) => {
155
166
  return app.model[m] !== i.model
156
167
  })
157
168
  })
158
169
 
159
- const application = await getAppConfig({ app, config })
160
170
  const exclude_list = lodash.get(application, 'exclude_list', [])
161
171
 
162
172
  const attributes = {
163
173
  exclude: Array.from(
164
174
  new Set([
165
- ...app.appConfig.loginData.attributes.exclude,
175
+ ...loginData.attributes.exclude,
166
176
  ...(Array.isArray(exclude_list) ? exclude_list : []),
167
177
  ])
168
178
  ),
@@ -342,20 +352,31 @@ exports.checkLogin = async (ctx) => {
342
352
  },
343
353
  ...app.include.user,
344
354
  ].filter((item) => item.model)
355
+
345
356
  if (app.appConfig.loginData) {
357
+ const application = await getAppConfig({ app, config })
358
+
359
+ const loginData = lodash.mergeWith(
360
+ app.appConfig.loginData,
361
+ lodash.get(application, 'loginData', {}),
362
+ (objValue, srcValue) => {
363
+ if (lodash.isArray(objValue)) {
364
+ return objValue.concat(srcValue)
365
+ }
366
+ }
367
+ )
346
368
  const include = includeDefault.filter((i) => {
347
- return app.appConfig.loginData.excludeInclude.every((m) => {
369
+ return loginData.excludeInclude.every((m) => {
348
370
  return app.model[m] !== i.model
349
371
  })
350
372
  })
351
373
 
352
- const application = await getAppConfig({ app, config })
353
374
  const exclude_list = lodash.get(application, 'exclude_list', [])
354
375
 
355
376
  const attributes = {
356
377
  exclude: Array.from(
357
378
  new Set([
358
- ...app.appConfig.loginData.attributes.exclude,
379
+ ...loginData.attributes.exclude,
359
380
  ...(Array.isArray(exclude_list) ? exclude_list : []),
360
381
  ])
361
382
  ),
@@ -442,12 +442,24 @@ exports.mp_login = async (ctx) => {
442
442
  ].filter((item) => item.model)
443
443
 
444
444
  if (app.appConfig.loginData) {
445
+ const application = await getAppConfig({ app, config })
446
+ const loginData = lodash.mergeWith(
447
+ app.appConfig.loginData,
448
+ lodash.get(application, 'loginData', {}),
449
+ (objValue, srcValue) => {
450
+ if (lodash.isArray(objValue)) {
451
+ return objValue.concat(srcValue)
452
+ }
453
+ }
454
+ )
445
455
  const include = includeDefault.filter((i) => {
446
- return app.appConfig.loginData.excludeInclude.every((m) => {
456
+ return loginData.excludeInclude.every((m) => {
447
457
  return app.model[m] !== i.model
448
458
  })
449
459
  })
450
- const { exclude_list = [] } = await getAppConfig({ app, config })
460
+
461
+ const exclude_list = lodash.get(application, 'exclude_list', [])
462
+
451
463
  const attributes = {
452
464
  exclude: Array.from(
453
465
  new Set([
@@ -925,9 +937,12 @@ exports.app_pay = async (ctx) => {
925
937
  // }
926
938
  const appConfig = getConfig(app)
927
939
 
928
- const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
929
- pay_config
930
- )
940
+ const {
941
+ mchId,
942
+ key,
943
+ partner_key,
944
+ appId: appid,
945
+ } = await appConfig.getObject(pay_config)
931
946
 
932
947
  if (!appid) throw new Error(`appId不能存在`)
933
948
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.0.0",
3
+ "version": "13.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {