q-koa 11.4.7 → 11.5.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 +8 -1
- package/core/errors.js +9 -0
- package/core/file/plugins/system/controller.js +30 -1
- package/package.json +1 -1
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
|
|
|
@@ -1930,13 +1930,20 @@ class APP {
|
|
|
1930
1930
|
APP.Sequelize = Sequelize
|
|
1931
1931
|
APP.lodash = _
|
|
1932
1932
|
APP.Random = Random
|
|
1933
|
+
|
|
1933
1934
|
APP.Validator = Validator
|
|
1934
1935
|
APP.ServiceError = ServiceError
|
|
1936
|
+
APP.TransactionError = TransactionError
|
|
1935
1937
|
APP.moment = moment
|
|
1938
|
+
|
|
1936
1939
|
global.moment = moment
|
|
1937
1940
|
global.Sequelize = Sequelize
|
|
1938
1941
|
global.lodash = _
|
|
1939
1942
|
|
|
1943
|
+
global.Validator = Validator
|
|
1944
|
+
global.ServiceError = ServiceError
|
|
1945
|
+
global.TransactionError = TransactionError
|
|
1946
|
+
|
|
1940
1947
|
APP.sleep = (time) => new Promise((resolve) => setTimeout(resolve, time * 1000))
|
|
1941
1948
|
|
|
1942
1949
|
APP.getService = (name) => {
|
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 {
|