q-koa 11.5.0 → 11.5.3
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
|
@@ -42,7 +42,7 @@ const {
|
|
|
42
42
|
miLimit,
|
|
43
43
|
} = require('./middlewares')
|
|
44
44
|
const Validator = require('./validator')
|
|
45
|
-
const { ServiceError } = require('./errors')
|
|
45
|
+
const { ServiceError, TransactionError } = require('./errors')
|
|
46
46
|
|
|
47
47
|
let spinner
|
|
48
48
|
|
|
@@ -1933,6 +1933,7 @@ APP.Random = Random
|
|
|
1933
1933
|
|
|
1934
1934
|
APP.Validator = Validator
|
|
1935
1935
|
APP.ServiceError = ServiceError
|
|
1936
|
+
APP.TransactionError = TransactionError
|
|
1936
1937
|
APP.moment = moment
|
|
1937
1938
|
|
|
1938
1939
|
global.moment = moment
|
|
@@ -1941,6 +1942,7 @@ global.lodash = _
|
|
|
1941
1942
|
|
|
1942
1943
|
global.Validator = Validator
|
|
1943
1944
|
global.ServiceError = ServiceError
|
|
1945
|
+
global.TransactionError = TransactionError
|
|
1944
1946
|
|
|
1945
1947
|
APP.sleep = (time) => new Promise((resolve) => setTimeout(resolve, time * 1000))
|
|
1946
1948
|
|
package/core/errors.js
CHANGED
|
@@ -5,4 +5,13 @@ class ServiceError extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
class TransactionError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message)
|
|
11
|
+
this.type = 'transaction'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
exports.ServiceError = ServiceError
|
|
16
|
+
|
|
17
|
+
exports.TransactionError = TransactionError
|
|
@@ -12,8 +12,9 @@ const cache = new LRU({
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
exports.initModel = async (ctx) => {
|
|
15
|
-
const { app } = getAppByCtx(ctx)
|
|
15
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
16
16
|
const { model, option } = ctx.request.body
|
|
17
|
+
|
|
17
18
|
const config = option
|
|
18
19
|
? {
|
|
19
20
|
[option]: true,
|
|
@@ -39,6 +40,34 @@ exports.initModel = async (ctx) => {
|
|
|
39
40
|
if (Object.keys(app.model[model]).length === 0) {
|
|
40
41
|
return ctx.ERROR('请检查,model为空')
|
|
41
42
|
}
|
|
43
|
+
if (app.appConfig.productionHost) {
|
|
44
|
+
const { data: productionModel } = await axios
|
|
45
|
+
.post(
|
|
46
|
+
`${app.appConfig.productionHost}/${appName}/system/getTable`,
|
|
47
|
+
{
|
|
48
|
+
model,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
headers: {
|
|
52
|
+
'client-type': 0,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
.then((res) => res.data)
|
|
57
|
+
const findList = Object.keys(productionModel).filter((key) => {
|
|
58
|
+
return (
|
|
59
|
+
!['id', 'created_at', 'createdid', 'updated_at'].includes(key) &&
|
|
60
|
+
!Object.keys(app.attributes[model]).includes(key)
|
|
61
|
+
)
|
|
62
|
+
})
|
|
63
|
+
if (findList.length > 0) {
|
|
64
|
+
return ctx.ERROR(
|
|
65
|
+
`${model} 线上字段 ${findList.join(
|
|
66
|
+
'/'
|
|
67
|
+
)} 不能被删除,请先修改线上model.js`
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
42
71
|
const result = await app.model[model].sync(config)
|
|
43
72
|
return ctx.SUCCESS(result)
|
|
44
73
|
} else {
|
|
@@ -214,6 +214,7 @@ exports.qr_code = async ({
|
|
|
214
214
|
scene,
|
|
215
215
|
is_oss = false,
|
|
216
216
|
config = 'weixin_mp',
|
|
217
|
+
width = 200,
|
|
217
218
|
}) => {
|
|
218
219
|
const appConfig = getConfig(app)
|
|
219
220
|
const { app_id, app_secrect } = await appConfig.getObject(config)
|
|
@@ -230,6 +231,7 @@ exports.qr_code = async ({
|
|
|
230
231
|
page,
|
|
231
232
|
is_hyaline,
|
|
232
233
|
scene,
|
|
234
|
+
width,
|
|
233
235
|
})
|
|
234
236
|
const qr_image = `https://${
|
|
235
237
|
site_host || 'api.kuashou.com'
|
|
@@ -252,6 +254,7 @@ exports.qr_code = async ({
|
|
|
252
254
|
page,
|
|
253
255
|
is_hyaline,
|
|
254
256
|
scene,
|
|
257
|
+
width,
|
|
255
258
|
})
|
|
256
259
|
const client = new OSS({
|
|
257
260
|
accessKeyId,
|