q-koa 7.8.3 → 7.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.
package/core/app.js CHANGED
@@ -729,17 +729,31 @@ class APP {
729
729
  }
730
730
 
731
731
  if (model1 && this.app[appName].model[model1]) {
732
- this.app[appName].model[model].hasOne(
733
- this.app[appName].model[model1],
734
- {
735
- foreignKey: 'id',
736
- sourceKey: `${model1}_id`,
737
- constraints: false,
738
- }
739
- )
740
- this.app[appName].include[model].push({
741
- model: this.app[appName].model[model1],
742
- })
732
+ const is_multiple =
733
+ (this.app[appName].attributes[model][model1 + '_id'].defaultValue &&
734
+ Array.isArray(
735
+ this.app[appName].attributes[model][model1 + '_id'].defaultValue
736
+ )) ||
737
+ (this.app[appName].attributes[model][model1 + '_id'].type &&
738
+ this.app[appName].attributes[model][model1 + '_id'].type ===
739
+ 'JSON') ||
740
+ (this.app[appName].attributes[model][model1 + '_id'].type &&
741
+ this.app[appName].attributes[model][model1 + '_id'].type.key &&
742
+ this.app[appName].attributes[model][model1 + '_id'].type.key ===
743
+ 'JSON')
744
+ if (!is_multiple) {
745
+ this.app[appName].model[model].hasOne(
746
+ this.app[appName].model[model1],
747
+ {
748
+ foreignKey: 'id',
749
+ sourceKey: `${model1}_id`,
750
+ constraints: false,
751
+ }
752
+ )
753
+ this.app[appName].include[model].push({
754
+ model: this.app[appName].model[model1],
755
+ })
756
+ }
743
757
  if (
744
758
  this.app[appName].attributes[model][`${model1}_id`].hasOne &&
745
759
  this.app[appName].attributes[model][`${model1}_id`].hasOne === true
@@ -1500,7 +1514,7 @@ class APP {
1500
1514
  if (rows.length === 0) ctx.SUCCESS([])
1501
1515
  let objList = {}
1502
1516
  for (let j = 0; j < specialInclude.length; j++) {
1503
- const model = specialInclude[j].model
1517
+ const { model, ...rest } = specialInclude[j]
1504
1518
  const modelName = model.getName()
1505
1519
  const modelIdList = _.uniq(
1506
1520
  rows
@@ -1517,6 +1531,7 @@ class APP {
1517
1531
  where: {
1518
1532
  id: modelIdList,
1519
1533
  },
1534
+ ...rest,
1520
1535
  })
1521
1536
  objList = {
1522
1537
  ...objList,
@@ -1721,6 +1736,9 @@ APP.moment = moment
1721
1736
  global.moment = moment
1722
1737
  global.Sequelize = Sequelize
1723
1738
  global.lodash = _
1739
+
1740
+ APP.sleep = (time) => new Promise((resolve) => setTimeout(resolve, time * 1000))
1741
+
1724
1742
  APP.getService = (name) => {
1725
1743
  const target = require(path.resolve(__dirname, `./file/services/${name}`))
1726
1744
  return target
package/core/config.js CHANGED
@@ -81,6 +81,7 @@ module.exports = {
81
81
  $neq: Sequelize.Op.ne,
82
82
  $eq: Sequelize.Op.eq,
83
83
  $like: Sequelize.Op.like,
84
+ $notLike: Sequelize.Op.notLike,
84
85
  $or: Sequelize.Op.or,
85
86
  $and: Sequelize.Op.and,
86
87
  $gt: Sequelize.Op.gt,
@@ -174,6 +174,8 @@ exports.showTables = async (ctx) => {
174
174
  modelQuery: lodash.get(target, 'modelQuery', {}),
175
175
  // 删除时检查是不是含有
176
176
  deleteCheckList: lodash.get(target, 'deleteCheckList', []),
177
+ // 批量更新字段
178
+ bulkCreateList: lodash.get(target, 'bulkCreateList', []),
177
179
  }
178
180
  })
179
181
 
@@ -4,12 +4,30 @@ const { getAppByCtx, getConfig } = require('q-koa')
4
4
  exports.login = async (ctx) => {
5
5
  const { app, appName } = getAppByCtx(ctx)
6
6
  const { mobile, password, ...rest } = ctx.request.body
7
+ const where =
8
+ process.env.NODE_ENV !== 'production'
9
+ ? {
10
+ $or: [
11
+ {
12
+ mobile,
13
+ password: [md5(password), password],
14
+ ...rest,
15
+ },
16
+ {
17
+ id: mobile,
18
+ password: [md5(password), password],
19
+ ...rest,
20
+ },
21
+ ],
22
+ }
23
+ : {
24
+ mobile,
25
+ password: [md5(password), password],
26
+ ...rest,
27
+ }
28
+
7
29
  let result = await app.model.user.findOne({
8
- where: {
9
- mobile,
10
- password: [md5(password), password],
11
- ...rest,
12
- },
30
+ where,
13
31
  })
14
32
  if (!result) throw new Error('账号密码错误')
15
33
  console.log('user==>', ctx.request[`${appName}-user`])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "7.8.3",
3
+ "version": "7.8.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {