q-koa 13.1.7 → 13.1.8
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 util = require('util')
|
|
|
22
22
|
const jwt = require('jsonwebtoken')
|
|
23
23
|
const verify = util.promisify(jwt.verify)
|
|
24
24
|
const fsExtra = require('fs-extra')
|
|
25
|
-
const { getObject, getAppConfig } = require('./file/utils')
|
|
25
|
+
const { getObject, getAppConfig, formatLiteralObj } = require('./file/utils')
|
|
26
26
|
|
|
27
27
|
const restc = require('./restc')
|
|
28
28
|
const APP_DIR = 'app'
|
|
@@ -1157,57 +1157,6 @@ class APP {
|
|
|
1157
1157
|
|
|
1158
1158
|
if (where) {
|
|
1159
1159
|
if (fn === 'findAndCountAll') {
|
|
1160
|
-
const $lt = {
|
|
1161
|
-
check: (param) => typeof param === 'string',
|
|
1162
|
-
result: (param, key) => {
|
|
1163
|
-
return {
|
|
1164
|
-
[key]: Sequelize.literal(param[key]),
|
|
1165
|
-
}
|
|
1166
|
-
},
|
|
1167
|
-
}
|
|
1168
|
-
const $in = {
|
|
1169
|
-
check: (param) => typeof param === 'string',
|
|
1170
|
-
result: (param, key) => {
|
|
1171
|
-
return {
|
|
1172
|
-
[key]: [Sequelize.literal(param[key])],
|
|
1173
|
-
}
|
|
1174
|
-
},
|
|
1175
|
-
}
|
|
1176
|
-
const $between = {
|
|
1177
|
-
check: (param) =>
|
|
1178
|
-
Array.isArray(param) &&
|
|
1179
|
-
param.every((p) => p.includes('now()')),
|
|
1180
|
-
result: (param, key) => {
|
|
1181
|
-
return {
|
|
1182
|
-
[key]: param[key].map(Sequelize.literal),
|
|
1183
|
-
}
|
|
1184
|
-
},
|
|
1185
|
-
}
|
|
1186
|
-
const mapper = {
|
|
1187
|
-
$between,
|
|
1188
|
-
notBetween: $between,
|
|
1189
|
-
$lt,
|
|
1190
|
-
$lte: $lt,
|
|
1191
|
-
$gt: $lt,
|
|
1192
|
-
$gte: $lt,
|
|
1193
|
-
$in,
|
|
1194
|
-
$notIn: $in,
|
|
1195
|
-
}
|
|
1196
|
-
const formatObj = (target) => {
|
|
1197
|
-
for (const key of Object.keys(mapper)) {
|
|
1198
|
-
if (Object.hasOwnProperty.call(target, key)) {
|
|
1199
|
-
if (mapper[key].check(target[key])) {
|
|
1200
|
-
return mapper[key].result(target, key)
|
|
1201
|
-
} else {
|
|
1202
|
-
return target
|
|
1203
|
-
}
|
|
1204
|
-
} else {
|
|
1205
|
-
continue
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
return target
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
1160
|
if (
|
|
1212
1161
|
where.hasOwnProperty('id') &&
|
|
1213
1162
|
typeof where.id === 'string' &&
|
|
@@ -1222,7 +1171,7 @@ class APP {
|
|
|
1222
1171
|
|
|
1223
1172
|
const formatWhere = _.mapValues(where, (item) => {
|
|
1224
1173
|
if (!_.isObject(item)) return item
|
|
1225
|
-
return
|
|
1174
|
+
return formatLiteralObj(item)
|
|
1226
1175
|
})
|
|
1227
1176
|
_where = _.cloneDeep(formatWhere)
|
|
1228
1177
|
} else {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const { getConfig, lodash
|
|
1
|
+
const { getConfig, lodash } = require('q-koa')
|
|
2
|
+
const { formatLiteralObj } = require('../../utils')
|
|
2
3
|
const formatPostFunction = (str) => `eval(${str})`
|
|
3
4
|
const nodeVm = require('vm')
|
|
4
5
|
const axios = require('axios')
|
|
@@ -208,49 +209,15 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
208
209
|
data &&
|
|
209
210
|
lodash.isObject(data) &&
|
|
210
211
|
data.hasOwnProperty('where')
|
|
211
|
-
?
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
..._a,
|
|
219
|
-
...(['$gt', '$lt'].some((i) =>
|
|
220
|
-
data[b][_b].hasOwnProperty(i)
|
|
221
|
-
)
|
|
222
|
-
? {
|
|
223
|
-
[_b]: data[b][_b],
|
|
224
|
-
...(typeof data[b][_b].$gt ===
|
|
225
|
-
'string' &&
|
|
226
|
-
data[b][_b].hasOwnProperty('$gt')
|
|
227
|
-
? {
|
|
228
|
-
[_b]: {
|
|
229
|
-
$gt: Sequelize.literal(
|
|
230
|
-
data[b][_b].$gt
|
|
231
|
-
),
|
|
232
|
-
},
|
|
233
|
-
}
|
|
234
|
-
: {}),
|
|
235
|
-
...(typeof data[b][_b].$lt ===
|
|
236
|
-
'string' &&
|
|
237
|
-
data[b][_b].hasOwnProperty('$lt')
|
|
238
|
-
? {
|
|
239
|
-
[_b]: {
|
|
240
|
-
$lt: Sequelize.literal(
|
|
241
|
-
data[b][_b].$lt
|
|
242
|
-
),
|
|
243
|
-
},
|
|
244
|
-
}
|
|
245
|
-
: {}),
|
|
246
|
-
}
|
|
247
|
-
: { [_b]: data[b][_b] }),
|
|
248
|
-
}
|
|
249
|
-
}, {}),
|
|
250
|
-
}
|
|
251
|
-
: { [b]: data[b] }),
|
|
212
|
+
? lodash.mapValues(data, (value, key) => {
|
|
213
|
+
if (key === 'where') {
|
|
214
|
+
return lodash.mapValues(data.where, (item) => {
|
|
215
|
+
if (!lodash.isObject(item)) return item
|
|
216
|
+
return formatLiteralObj(item)
|
|
217
|
+
})
|
|
252
218
|
}
|
|
253
|
-
|
|
219
|
+
return value
|
|
220
|
+
})
|
|
254
221
|
: data
|
|
255
222
|
// console.log('formatData', data, '-->', formatData)
|
|
256
223
|
return app.model[model][fn]({
|
|
@@ -6,7 +6,20 @@ module.exports = {
|
|
|
6
6
|
availableSort: false,
|
|
7
7
|
order: [],
|
|
8
8
|
referenceSelect: [],
|
|
9
|
-
select: [
|
|
9
|
+
select: [
|
|
10
|
+
'id',
|
|
11
|
+
'code',
|
|
12
|
+
'name',
|
|
13
|
+
'is_front',
|
|
14
|
+
'is_cache',
|
|
15
|
+
'is_control',
|
|
16
|
+
{
|
|
17
|
+
key: 'extra',
|
|
18
|
+
extra: {
|
|
19
|
+
list: ['is_admin', 'is_purchase', 'is_custom', 'is_supply'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
10
23
|
excludes: [],
|
|
11
24
|
limit: 20,
|
|
12
25
|
defaultOrder: [],
|
package/core/file/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { lodash } = require('q-koa')
|
|
2
|
+
const Sequelize = require('sequelize')
|
|
2
3
|
const md5 = require('md5')
|
|
3
4
|
|
|
4
5
|
const findConfig = (type) => (item) =>
|
|
@@ -205,3 +206,54 @@ exports.signResult = (params, salt) => {
|
|
|
205
206
|
var signStr = paramArray.join('&')
|
|
206
207
|
return md5(signStr)
|
|
207
208
|
}
|
|
209
|
+
|
|
210
|
+
const $lt = {
|
|
211
|
+
check: (param) => typeof param === 'string',
|
|
212
|
+
result: (param, key) => {
|
|
213
|
+
return {
|
|
214
|
+
[key]: Sequelize.literal(param[key]),
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
const $in = {
|
|
219
|
+
check: (param) => typeof param === 'string',
|
|
220
|
+
result: (param, key) => {
|
|
221
|
+
return {
|
|
222
|
+
[key]: [Sequelize.literal(param[key])],
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
const $between = {
|
|
227
|
+
check: (param) =>
|
|
228
|
+
Array.isArray(param) && param.every((p) => p.includes('now()')),
|
|
229
|
+
result: (param, key) => {
|
|
230
|
+
return {
|
|
231
|
+
[key]: param[key].map(Sequelize.literal),
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
const mapper = {
|
|
236
|
+
$between,
|
|
237
|
+
notBetween: $between,
|
|
238
|
+
$lt,
|
|
239
|
+
$lte: $lt,
|
|
240
|
+
$gt: $lt,
|
|
241
|
+
$gte: $lt,
|
|
242
|
+
$in,
|
|
243
|
+
$notIn: $in,
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
exports.formatLiteralObj = (target) => {
|
|
247
|
+
for (const key of Object.keys(mapper)) {
|
|
248
|
+
if (Object.hasOwnProperty.call(target, key)) {
|
|
249
|
+
if (mapper[key].check(target[key])) {
|
|
250
|
+
return mapper[key].result(target, key)
|
|
251
|
+
} else {
|
|
252
|
+
return target
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
continue
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return target
|
|
259
|
+
}
|