q-koa 10.8.5 → 10.8.7

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
@@ -344,7 +344,7 @@ class APP {
344
344
  if (typeof item === 'string') {
345
345
  return {
346
346
  app: item,
347
- db: item,
347
+ db: this.config.db.name || item,
348
348
  }
349
349
  } else {
350
350
  return item
package/core/config.js CHANGED
@@ -137,6 +137,7 @@ module.exports = {
137
137
  if (app.controller.cache) {
138
138
  router.get('/cache/get', app.controller.cache.get)
139
139
  router.get('/cache/clear', app.controller.cache.clear)
140
+ router.get('/cache/getAll', app.controller.cache.getAll)
140
141
  }
141
142
  if (app.model.weixin) {
142
143
  router.get('/weixin/h5_login', app.controller.weixin.h5_login)
@@ -0,0 +1,57 @@
1
+ const { getAppByCtx, getUserByCtx, getConfig, lodash } = require('q-koa')
2
+
3
+ exports.login = async (ctx) => {
4
+ const { app, appName } = getAppByCtx(ctx)
5
+ const user_id = getUserByCtx(ctx)
6
+ const appConfig = getConfig(app)
7
+ const { is_dev } = await appConfig.getObject('base')
8
+ const { uuid } = ctx.request.body
9
+ console.log(uuid)
10
+ if (!app.attributes.user.uuid) throw new Error(`没有uuid字段`)
11
+
12
+ const hasUser = await app.model.user.findOne({
13
+ where: {
14
+ uuid,
15
+ },
16
+ })
17
+
18
+ let result = null
19
+ if (!hasUser) {
20
+ result = await app.model.user.create({
21
+ uuid,
22
+ })
23
+ } else {
24
+ result = hasUser
25
+ }
26
+
27
+ const tokenResult = {
28
+ id: result.id,
29
+ name: result.name,
30
+ mobile: result.mobile,
31
+ h5_user: result.h5_user
32
+ ? {
33
+ openid: result.h5_user && result.h5_user.openid,
34
+ }
35
+ : null,
36
+ mp_user: result.mp_user
37
+ ? {
38
+ openid: result.mp_user && result.mp_user.openid,
39
+ }
40
+ : null,
41
+ toutiao_user: result.toutiao_user
42
+ ? {
43
+ openid: result.toutiao_user && result.toutiao_user.openid,
44
+ }
45
+ : null,
46
+ }
47
+ const token = await app.sign({
48
+ user: tokenResult,
49
+ })
50
+
51
+ return ctx.SUCCESS({
52
+ token,
53
+ user: app.appConfig.loginData
54
+ ? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
55
+ : result,
56
+ })
57
+ }
@@ -1,5 +1,12 @@
1
1
  const { getAppByCtx, getUserByCtx, getConfig } = require('q-koa')
2
2
 
3
+ exports.getAll = async (ctx) => {
4
+ const { app, appName } = getAppByCtx(ctx)
5
+ const result = Object.keys(app.model).filter((model) => app.cache.get(model))
6
+ console.info(`cacheModel设置可CRUD同步更新`)
7
+ ctx.SUCCESS(result)
8
+ }
9
+
3
10
  exports.get = async (ctx) => {
4
11
  const { app, appName } = getAppByCtx(ctx)
5
12
  const key =
@@ -203,7 +203,7 @@ exports.getTable = async (ctx) => {
203
203
  show_virtual = false,
204
204
  is_cache = true,
205
205
  } = ctx.request.body
206
-
206
+ if (_model === 'page') return ctx.SUCCESS({})
207
207
  if (is_cache && app.cache && app.cache.get(`${_model}-table`)) {
208
208
  return ctx.SUCCESS(app.cache.get(`${_model}-table`))
209
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "10.8.5",
3
+ "version": "10.8.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {