q-koa 12.5.0 → 12.5.1

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
@@ -945,6 +945,7 @@ class APP {
945
945
  'destroy',
946
946
  'bulkCreate',
947
947
  'count',
948
+ 'sum',
948
949
  ].includes(fn)
949
950
  ) {
950
951
  const excludeAuth =
@@ -959,7 +960,9 @@ class APP {
959
960
  await app[appName][hooksList[i]][controller][fn](ctx)
960
961
  }
961
962
  }
962
- if (['findOne', 'findAll', 'findAndCountAll', 'count'].includes(fn)) {
963
+ if (
964
+ ['findOne', 'findAll', 'findAndCountAll', 'count', 'sum'].includes(fn)
965
+ ) {
963
966
  const {
964
967
  where,
965
968
  limit,
@@ -1169,6 +1172,24 @@ class APP {
1169
1172
  })
1170
1173
  ctx.SUCCESS(result)
1171
1174
  }
1175
+ if (fn === 'sum') {
1176
+ const requiredInclude = myInclude.filter(
1177
+ (item) =>
1178
+ (item.where && !item.hasOwnProperty('required')) ||
1179
+ (item.hasOwnProperty('required') && item.required)
1180
+ )
1181
+ if (!(attributes && attributes.length === 1)) {
1182
+ throw new Error(`${fn}方法需要attributes一个`)
1183
+ }
1184
+ const result = await app[appName].model[controller][fn](
1185
+ attributes[0],
1186
+ {
1187
+ where: _where,
1188
+ include: requiredInclude,
1189
+ }
1190
+ )
1191
+ ctx.SUCCESS(result)
1192
+ }
1172
1193
  if (['findOne', 'findAll', 'findAndCountAll'].includes(fn)) {
1173
1194
  // 拆分
1174
1195
  if (is_split) {
@@ -135,7 +135,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
135
135
  if (app.controller[model] && app.controller[model][fn]) {
136
136
  return app.controller[model][fn](ctx, data).then((result) => {
137
137
  if (!result && process.env.NODE_ENV !== 'production') {
138
- console.log(`需要在控制器${fn}中返回`)
138
+ console.error(`需要在控制器${fn}中返回`)
139
139
  }
140
140
  return {
141
141
  [item]: result,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.5.0",
3
+ "version": "12.5.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {