q-koa 13.0.0 → 13.0.1

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
@@ -925,9 +925,12 @@ exports.app_pay = async (ctx) => {
925
925
  // }
926
926
  const appConfig = getConfig(app)
927
927
 
928
- const { mchId, key, partner_key, appId: appid } = await appConfig.getObject(
929
- pay_config
930
- )
928
+ const {
929
+ mchId,
930
+ key,
931
+ partner_key,
932
+ appId: appid,
933
+ } = await appConfig.getObject(pay_config)
931
934
 
932
935
  if (!appid) throw new Error(`appId不能存在`)
933
936
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.0.0",
3
+ "version": "13.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {