q-koa 10.5.0 → 10.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 +12 -5
- package/core/file/plugins/system/controller.js +49 -0
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -362,15 +362,16 @@ class APP {
|
|
|
362
362
|
)
|
|
363
363
|
|
|
364
364
|
try {
|
|
365
|
-
const
|
|
365
|
+
const dbName = this.config.db.name || appName
|
|
366
|
+
const db = connectDatabase(dbName)(this.config.db)
|
|
366
367
|
if (!is_dev) {
|
|
367
368
|
if (!dbFlag) {
|
|
368
|
-
console.log(chalk.green(`检查${
|
|
369
|
+
console.log(chalk.green(`检查${dbName}数据库`))
|
|
369
370
|
await db.authenticate()
|
|
370
371
|
dbFlag = true
|
|
371
372
|
}
|
|
372
373
|
} else {
|
|
373
|
-
console.log(chalk.green(`检查${
|
|
374
|
+
console.log(chalk.green(`检查${dbName}数据库`))
|
|
374
375
|
await db.authenticate()
|
|
375
376
|
}
|
|
376
377
|
const configPath = `${rootDirectory}/${APP_DIR}/${appName}/config.js`
|
|
@@ -956,6 +957,7 @@ class APP {
|
|
|
956
957
|
excludeInclude,
|
|
957
958
|
raw = false,
|
|
958
959
|
is_split = false,
|
|
960
|
+
autoInclude = true,
|
|
959
961
|
omit = [],
|
|
960
962
|
...other
|
|
961
963
|
} = ctx.request.body
|
|
@@ -1008,7 +1010,10 @@ class APP {
|
|
|
1008
1010
|
? _.uniqWith(
|
|
1009
1011
|
[
|
|
1010
1012
|
...strInclude,
|
|
1011
|
-
...
|
|
1013
|
+
...(autoInclude
|
|
1014
|
+
? app[appName].include[controller]
|
|
1015
|
+
: []
|
|
1016
|
+
).filter((item) => {
|
|
1012
1017
|
return !strInclude.some(
|
|
1013
1018
|
(i) =>
|
|
1014
1019
|
(i.model && i.model.getName()) ===
|
|
@@ -1023,7 +1028,9 @@ class APP {
|
|
|
1023
1028
|
myInclude = null
|
|
1024
1029
|
} else {
|
|
1025
1030
|
myInclude = app[appName].include
|
|
1026
|
-
?
|
|
1031
|
+
? autoInclude
|
|
1032
|
+
? app[appName].include[controller]
|
|
1033
|
+
: []
|
|
1027
1034
|
: null
|
|
1028
1035
|
}
|
|
1029
1036
|
|
|
@@ -527,3 +527,52 @@ exports.mockPay = async (ctx) => {
|
|
|
527
527
|
})
|
|
528
528
|
ctx.SUCCESS('ok')
|
|
529
529
|
}
|
|
530
|
+
|
|
531
|
+
exports.copyOther = async (ctx) => {
|
|
532
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
533
|
+
|
|
534
|
+
const { model, source } = ctx.request.body
|
|
535
|
+
if (!model) return ctx.ERROR('model?')
|
|
536
|
+
if (!source) return ctx.ERROR('source? https://www.kuashou.com/kuashou')
|
|
537
|
+
let list = []
|
|
538
|
+
if (Array.isArray(model)) {
|
|
539
|
+
list = model
|
|
540
|
+
} else {
|
|
541
|
+
if (model !== 'all') {
|
|
542
|
+
list = [model]
|
|
543
|
+
} else {
|
|
544
|
+
const result = await app.sequelize.showAllSchemas()
|
|
545
|
+
list = result.map((item) => item[`Tables_in_${appName}`])
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const prefix = `${source}`
|
|
550
|
+
let successList = []
|
|
551
|
+
let failList = []
|
|
552
|
+
for (let i = 0; i < list.length; i++) {
|
|
553
|
+
const url = `${prefix}/${list[i]}/findAll`
|
|
554
|
+
|
|
555
|
+
const result = await axios.post(url).then((res) => res.data)
|
|
556
|
+
console.log(list[i])
|
|
557
|
+
if (result.code === 200) {
|
|
558
|
+
await app.model[list[i]].sync({
|
|
559
|
+
force: true,
|
|
560
|
+
})
|
|
561
|
+
try {
|
|
562
|
+
await app.model[list[i]].bulkCreate(
|
|
563
|
+
result.data.map((i) => lodash.omitBy(i, lodash.isNull)),
|
|
564
|
+
{}
|
|
565
|
+
)
|
|
566
|
+
successList = [...successList, list[i]]
|
|
567
|
+
} catch (e) {
|
|
568
|
+
console.log(e.message)
|
|
569
|
+
failList = [...failList, list[i]]
|
|
570
|
+
}
|
|
571
|
+
} else {
|
|
572
|
+
console.log(url, result.data)
|
|
573
|
+
failList = [...failList, list[i]]
|
|
574
|
+
continue
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
ctx.SUCCESS({ successList, failList })
|
|
578
|
+
}
|