q-koa 13.1.6 → 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 +2 -53
- package/core/file/plugins/app/controller.js +0 -1
- package/core/file/plugins/douyin/controller.js +0 -1
- package/core/file/plugins/system/service.js +10 -43
- package/core/file/plugins/table_setting/config.js +14 -1
- package/core/file/plugins/toutiao/controller.js +0 -3
- package/core/file/plugins/user/controller.js +0 -3
- package/core/file/plugins/weixin/controller.js +0 -5
- package/core/file/utils/index.js +52 -0
- package/package.json +1 -1
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: [],
|
|
@@ -161,12 +161,9 @@ exports.login = async (ctx) => {
|
|
|
161
161
|
],
|
|
162
162
|
})
|
|
163
163
|
|
|
164
|
-
console.log('result', result, app.include.user)
|
|
165
|
-
|
|
166
164
|
const tokenResult = {
|
|
167
165
|
id: result.id,
|
|
168
166
|
name: result.name,
|
|
169
|
-
mobile: result.mobile,
|
|
170
167
|
mp_user: result.mp_user
|
|
171
168
|
? {
|
|
172
169
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -42,7 +42,6 @@ exports.login = async (ctx) => {
|
|
|
42
42
|
const tokenResult = {
|
|
43
43
|
id: result.id,
|
|
44
44
|
name: result.name,
|
|
45
|
-
mobile: result.mobile,
|
|
46
45
|
}
|
|
47
46
|
const token = await app.sign({
|
|
48
47
|
user: tokenResult,
|
|
@@ -194,7 +193,6 @@ exports.login = async (ctx) => {
|
|
|
194
193
|
const tokenResult = {
|
|
195
194
|
id: result.id,
|
|
196
195
|
name: result.name,
|
|
197
|
-
mobile: result.mobile,
|
|
198
196
|
mp_user: result.mp_user
|
|
199
197
|
? {
|
|
200
198
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -433,7 +431,6 @@ exports.checkLogin = async (ctx) => {
|
|
|
433
431
|
const tokenResult = {
|
|
434
432
|
id: result.id,
|
|
435
433
|
name: result.name,
|
|
436
|
-
mobile: result.mobile,
|
|
437
434
|
mp_user: result.mp_user
|
|
438
435
|
? {
|
|
439
436
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -131,7 +131,6 @@ exports.mp_getPhone = async (ctx) => {
|
|
|
131
131
|
const tokenResult = {
|
|
132
132
|
id: result.id,
|
|
133
133
|
name: result.name,
|
|
134
|
-
mobile: result.mobile,
|
|
135
134
|
mp_user: result.mp_user
|
|
136
135
|
? {
|
|
137
136
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -253,7 +252,6 @@ exports.mp_getPhoneNew = async (ctx) => {
|
|
|
253
252
|
const tokenResult = {
|
|
254
253
|
id: result.id,
|
|
255
254
|
name: result.name,
|
|
256
|
-
mobile: result.mobile,
|
|
257
255
|
mp_user: result.mp_user
|
|
258
256
|
? {
|
|
259
257
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -495,7 +493,6 @@ exports.mp_login = async (ctx) => {
|
|
|
495
493
|
const tokenResult = {
|
|
496
494
|
id: result.id,
|
|
497
495
|
name: result.name,
|
|
498
|
-
mobile: result.mobile,
|
|
499
496
|
mp_user: result.mp_user
|
|
500
497
|
? {
|
|
501
498
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -675,7 +672,6 @@ exports.h5_login_callback = async (ctx) => {
|
|
|
675
672
|
const tokenResult = {
|
|
676
673
|
id: result.id,
|
|
677
674
|
name: result.name,
|
|
678
|
-
mobile: result.mobile,
|
|
679
675
|
mp_user: result.mp_user
|
|
680
676
|
? {
|
|
681
677
|
openid: result.mp_user && result.mp_user.openid,
|
|
@@ -810,7 +806,6 @@ exports.h5_login_info_callback = async (ctx) => {
|
|
|
810
806
|
const tokenResult = {
|
|
811
807
|
id: result.id,
|
|
812
808
|
name: result.name,
|
|
813
|
-
mobile: result.mobile,
|
|
814
809
|
mp_user: result.mp_user
|
|
815
810
|
? {
|
|
816
811
|
openid: result.mp_user && result.mp_user.openid,
|
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
|
+
}
|