q-koa 8.8.5 → 8.8.6

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.
@@ -48,3 +48,56 @@ exports.copyOther = async (ctx) => {
48
48
 
49
49
  ctx.SUCCESS('ok')
50
50
  }
51
+
52
+ exports.init = async (ctx) => {
53
+ const { app, appName } = getAppByCtx(ctx)
54
+
55
+ const parentList = await app.model.setting.findAll({
56
+ where: {
57
+ parent_id: 0,
58
+ },
59
+ order: [['id', 'ASC']],
60
+ raw: true,
61
+ })
62
+
63
+ let list = []
64
+ let number = 0
65
+ for (let i = 0; i < parentList.length; i++) {
66
+ number += 1
67
+ const { id: parent_id, ...rest } = parentList[i]
68
+ list = [
69
+ ...list,
70
+ {
71
+ id: number,
72
+ ...rest,
73
+ parent_id: 0,
74
+ },
75
+ ]
76
+ const childList = await app.model.setting.findAll({
77
+ where: {
78
+ parent_id,
79
+ },
80
+ order: [['id', 'ASC']],
81
+ raw: true,
82
+ })
83
+ list = [
84
+ ...list,
85
+ ...childList.map((item, index) => {
86
+ const { id: child_id, ...restChild } = item
87
+ const id = number + index + 1
88
+
89
+ return {
90
+ id,
91
+ ...restChild,
92
+ parent_id: number,
93
+ }
94
+ }),
95
+ ]
96
+ number += childList.length
97
+ }
98
+
99
+ await app.model.setting.sync({ force: true })
100
+ await app.model.setting.bulkCreate(list)
101
+
102
+ ctx.SUCCESS(list)
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.8.5",
3
+ "version": "8.8.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {