q-koa 8.9.4 → 9.0.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.
@@ -96,8 +96,15 @@ exports.initRoute = async (ctx) => {
96
96
  },
97
97
  ]
98
98
 
99
- const permissionList = await app.model.permission.findAll()
100
- const modelList = await app.model.model.findAll()
99
+ const permissionList = await app.model.permission.findAll({
100
+ attributes: ['id', 'name', 'controller'],
101
+ raw: true,
102
+ })
103
+ const modelList = await app.model.model.findAll({
104
+ attributes: ['id', 'belongs', 'model'],
105
+ raw: true,
106
+ })
107
+
101
108
  const roleList = await app.model.role.findAll()
102
109
  const rolePermission = lodash.uniq(
103
110
  roleList
@@ -105,7 +112,7 @@ exports.initRoute = async (ctx) => {
105
112
  .reduce((a, b) => [...a, ...b.permission_id], [])
106
113
  )
107
114
  for (let i = 0; i < permissionList.length; i++) {
108
- const target = permissionList[i].toJSON()
115
+ const target = permissionList[i]
109
116
  if (target.controller === '') {
110
117
  await app.model.permission.destroy({
111
118
  where: {
@@ -128,18 +135,20 @@ exports.initRoute = async (ctx) => {
128
135
  const is_project = !model
129
136
  list = [
130
137
  ...list,
131
- {
132
- name: target.name,
133
- parent_id,
134
- url: is_project ? `/project/${appName}/` + target.controller : '',
135
- model_id: model ? model.id : 0,
136
- key: is_project
137
- ? ''
138
- : model && model.belongs
139
- ? `${model.belongs}/${model.model}`
140
- : '',
141
- },
142
- ]
138
+ model
139
+ ? {
140
+ name: target.name,
141
+ parent_id,
142
+ url: is_project ? `/project/` + target.controller : '',
143
+ model_id: model ? model.id : 0,
144
+ key: is_project
145
+ ? ''
146
+ : model && model.belongs
147
+ ? `${model.belongs}/${model.model}`
148
+ : '',
149
+ }
150
+ : null,
151
+ ].filter(Boolean)
143
152
  }
144
153
  const sortList = list.map((item) => {
145
154
  const sort = routesList.find((r) => r.name === item.name)
@@ -1,6 +1,7 @@
1
1
  const { getConfig, lodash } = require('q-koa')
2
2
  const formatPostFunction = (str) => `eval(${str})`
3
3
  const nodeVm = require('vm')
4
+ const axios = require('axios')
4
5
 
5
6
  exports.initData = async ({ includes, excludes, app, ctx }) => {
6
7
  const appConfig = getConfig(app)
@@ -69,7 +69,7 @@ module.exports = class Singleton {
69
69
  const Print = new yly.Print(RpcClient)
70
70
  const res = await Print.index(this.config.machine_code, order_id, content)
71
71
 
72
- if (res.code !== '0') {
72
+ if (res && res.error_description !== 'success') {
73
73
  throw new Error(res.error_description)
74
74
  }
75
75
  } catch (e) {
@@ -100,7 +100,14 @@ module.exports = class Singleton {
100
100
  return cache.get(appid)
101
101
  }
102
102
  const url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
103
- const { access_token } = await axios.get(url).then((res) => res.data)
103
+
104
+ const result = await axios.get(url).then((res) => res.data)
105
+ const { errcode, errmsg, access_token } = result
106
+
107
+ if (errcode) {
108
+ throw new Error(errmsg)
109
+ }
110
+
104
111
  cache.set(appid, access_token)
105
112
  return access_token
106
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.9.4",
3
+ "version": "9.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {