q-koa 13.3.7 → 13.3.9

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.
@@ -646,6 +646,10 @@ exports.gpt = async (ctx) => {
646
646
  statusCode = 500
647
647
  ctx.response.status = statusCode
648
648
  }
649
+
650
+ if (e.response.status === 400) {
651
+ throw new Error(e.response.data.message)
652
+ }
649
653
  throw new Error(e.message)
650
654
  })
651
655
 
@@ -29,3 +29,16 @@ exports.clearWeixin = async (ctx) => {
29
29
  })
30
30
  )
31
31
  }
32
+
33
+ exports.push = async (ctx) => {
34
+ const { app, appName } = getAppByCtx(ctx)
35
+
36
+ const { message = '测试通知' } = ctx.request.body
37
+
38
+ await app.service.log.push({
39
+ app,
40
+ message,
41
+ })
42
+
43
+ ctx.SUCCESS('ok')
44
+ }
@@ -104,9 +104,10 @@ exports.countAndMaxId = async (ctx, _data) => {
104
104
 
105
105
  const mapper = {
106
106
  TINYINT: 255,
107
- SMALLINIT: 65535,
107
+ SMALLINT: 65535,
108
108
  MEDIUMINT: 16777215,
109
109
  INT: 4294967295,
110
+ BIGINT: 18446744073709551615,
110
111
  }
111
112
  let availableId = 0
112
113
  for (const _type in mapper) {
@@ -188,6 +189,9 @@ exports.initModel = async (ctx) => {
188
189
  }
189
190
  )
190
191
  .then((res) => res.data)
192
+ .catch((e) => {
193
+ return Promise.resolve({})
194
+ })
191
195
  if (code === 200) {
192
196
  const findList = Object.keys(productionModel || {}).filter((key) => {
193
197
  return (
@@ -990,8 +994,10 @@ exports.changeIdType = async (ctx) => {
990
994
 
991
995
  const mapper = {
992
996
  INTEGER: 'INT',
997
+ SMALLINT: 'SMALLINT',
993
998
  TINYINT: 'TINYINT',
994
999
  MEDIUMINT: 'MEDIUMINT',
1000
+ BIGINT: 'BIGINT',
995
1001
  }
996
1002
  if (!mapper[idType]) return ctx.ERROR(`not accept ${idType}`)
997
1003
 
@@ -1002,19 +1008,43 @@ exports.changeIdType = async (ctx) => {
1002
1008
 
1003
1009
  const query = `ALTER TABLE \`${model}\` MODIFY COLUMN id ${updateTo} NOT NULL AUTO_INCREMENT`
1004
1010
 
1005
- const target = lodash.pickBy(app.attributes, (obj) => `${model}_id` in obj)
1006
-
1011
+ const target = lodash.pickBy(app.attributes, (obj) => {
1012
+ return (
1013
+ `${model}_id` in obj ||
1014
+ Object.keys(obj).some(
1015
+ (k) => obj[k].belongsTo && obj[k].belongsTo === model
1016
+ )
1017
+ )
1018
+ })
1019
+ // console.log('target', app.attributes.store_balance_date)
1007
1020
  console.log(`即将更新${model}的ID类型为${updateTo}`)
1008
1021
  let error_message = ''
1009
1022
  let flag = true
1010
1023
  for (const _model of Object.keys(target)) {
1011
1024
  const _res = await app.sequelize.getQueryInterface().describeTable(_model)
1012
- if (updateTo !== _res[`${model}_id`].type) {
1013
- error_message = `请先处理好${_model}的字段类型${model}_id,当前是${
1014
- _res[`${model}_id`].type
1015
- }`
1016
- console.error(error_message)
1017
- flag = false
1025
+ if (_res[`${model}_id`]) {
1026
+ if (
1027
+ updateTo !== _res[`${model}_id`].type &&
1028
+ !['JSON'].includes(_res[`${model}_id`].type)
1029
+ ) {
1030
+ error_message = `请先处理好${_model}的字段类型${model}_id,当前是${
1031
+ _res[`${model}_id`].type
1032
+ }`
1033
+ console.error(error_message)
1034
+ flag = false
1035
+ }
1036
+ } else {
1037
+ const targetAttribute = lodash.pickBy(app.attributes[_model], (obj) => {
1038
+ return obj.belongsTo && obj.belongsTo === model
1039
+ })
1040
+
1041
+ if (updateTo !== _res[Object.keys(targetAttribute)[0]].type) {
1042
+ error_message = `请先处理好${_model}的字段类型${
1043
+ Object.keys(targetAttribute)[0]
1044
+ },当前是${_res[Object.keys(targetAttribute)[0]].type}`
1045
+ console.error(error_message)
1046
+ flag = false
1047
+ }
1018
1048
  }
1019
1049
  }
1020
1050
  if (obj.type === updateTo) {
@@ -1027,6 +1057,6 @@ exports.changeIdType = async (ctx) => {
1027
1057
  // ctx.SUCCESS(query)
1028
1058
 
1029
1059
  const result = await app.sequelize.query(query)
1030
-
1060
+ console.log('更新成功')
1031
1061
  ctx.SUCCESS(result)
1032
1062
  }
@@ -1917,11 +1917,11 @@ exports.getUserPortrait = async (ctx) => {
1917
1917
  ctx.SUCCESS(result)
1918
1918
  }
1919
1919
 
1920
- exports.getVisitTrend = async (ctx) => {
1920
+ exports.getVisitTrend = async (ctx, _data) => {
1921
1921
  const { app, appName } = getAppByCtx(ctx)
1922
1922
  const appConfig = getConfig(app)
1923
1923
 
1924
- const { config = 'weixin_mp', type = 'day', date } = ctx.request.body
1924
+ const { config = 'weixin_mp', type = 'day', date } = _data || ctx.request.body
1925
1925
  const { app_id, app_secrect } = await appConfig.getObject(config)
1926
1926
 
1927
1927
  const diff = moment().hour() > 8 ? -1 : -2
@@ -1963,8 +1963,17 @@ exports.getVisitTrend = async (ctx) => {
1963
1963
  weixinMp.init()
1964
1964
 
1965
1965
  const result = await weixinMp.getVisitTrend({ ...obj, type })
1966
- await app.model.weixin_visit.create(result.list[0])
1966
+ if (result && result.list && result.list[0]) {
1967
+ await app.model.weixin_visit.create(result.list[0])
1968
+ } else {
1969
+ return app.controller.weixin.getVisitTrend(ctx, {
1970
+ type,
1971
+ date: moment(date).add(-1, 'days').format('YYYYMMDD'),
1972
+ })
1973
+ }
1974
+
1967
1975
  ctx.SUCCESS(result)
1976
+ return result
1968
1977
  }
1969
1978
 
1970
1979
  exports.getCommentInfo = async (ctx, _data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.3.7",
3
+ "version": "13.3.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {