q-koa 9.0.4 → 9.1.0

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
@@ -926,6 +926,24 @@ class APP {
926
926
  }
927
927
  }
928
928
 
929
+ if (fn === 'findAll') {
930
+ const disabledFindAllList = _.get(
931
+ app[appName],
932
+ 'appConfig.disabledFindAllList',
933
+ []
934
+ )
935
+ if (
936
+ disabledFindAllList.includes(controller) &&
937
+ !(
938
+ limit >= 0 ||
939
+ limit !== undefined ||
940
+ (where && !_.isEmpty(where))
941
+ )
942
+ ) {
943
+ throw new Error(`请使用条件`)
944
+ }
945
+ }
946
+
929
947
  let myInclude
930
948
  if (include) {
931
949
  if (relate) {
package/core/config.js CHANGED
@@ -131,6 +131,7 @@ module.exports = {
131
131
  excludes: ['admin'],
132
132
  },
133
133
  cacheModel: [],
134
+ disabledFindAllList: [],
134
135
  defaultRouter: (router) => (app) => {
135
136
  if (app.controller.cache) {
136
137
  router.get('/cache/get', app.controller.cache.get)
@@ -60,6 +60,15 @@ exports.loadModel = async ({ app, appName }) => {
60
60
  // const ori_target = modelList.find((m) => m.model === result[i])
61
61
  // const id = ori_target ? ori_target.id : null
62
62
  const id = i + 1
63
+
64
+ let countNumber = 0
65
+ if (app.model[result[i]]) {
66
+ countNumber = await app.model[result[i]].count()
67
+ }
68
+ if (countNumber >= 500) {
69
+ disabledFindAllList = [...disabledFindAllList, result[i]]
70
+ }
71
+
63
72
  const obj = {
64
73
  id,
65
74
  model: result[i],
@@ -211,6 +220,8 @@ exports.loadModel = async ({ app, appName }) => {
211
220
 
212
221
  await Promise.all([promise1, promise2])
213
222
  console.log('lodaModel success!')
223
+ console.warn(`disabledFindAllList: ${JSON.stringify(disabledFindAllList)}`)
224
+
214
225
  if (app.service.routes && app.model.routes) {
215
226
  await app.service.routes.initRouter({ app })
216
227
  } else {
@@ -4,7 +4,16 @@ module.exports = {
4
4
  multiple: false,
5
5
  availableSort: true,
6
6
  order: [],
7
- select: [{ key: 'parent_id' }],
7
+ select: [
8
+ { key: 'parent_id' },
9
+ {
10
+ key: 'key',
11
+ },
12
+ {
13
+ key: 'url',
14
+ symbol: '$like',
15
+ },
16
+ ],
8
17
  excludes: [],
9
18
  limit: 40,
10
19
  defaultOrder: [{ sort: 'ascending', type: 'sortOrder' }],
@@ -206,8 +206,9 @@ exports.getTable = async (ctx) => {
206
206
 
207
207
  const _result = await app.sequelize.getQueryInterface().describeTable(model)
208
208
 
209
+ const modelAttributes = lodash.cloneDeep(app.attributes[model])
209
210
  const result = lodash.pick(_result, [
210
- ...Object.keys(app.attributes[model]),
211
+ ...Object.keys(modelAttributes),
211
212
  'id',
212
213
  'createdid',
213
214
  'updated_at',
@@ -217,10 +218,10 @@ exports.getTable = async (ctx) => {
217
218
  const obj = {}
218
219
  if (show_virtual) {
219
220
  Array.from(
220
- new Set([...Object.keys(result), ...Object.keys(app.attributes[model])])
221
+ new Set([...Object.keys(result), ...Object.keys(modelAttributes)])
221
222
  ).forEach((attr) => {
222
223
  obj[attr] = lodash.merge(
223
- app.attributes[model][attr],
224
+ modelAttributes[attr],
224
225
  lodash.omitBy(result[attr], lodash.isNull),
225
226
  app.config[_model].comment && app.config[_model].comment
226
227
  ? app.config[_model].comment[attr]
@@ -230,7 +231,7 @@ exports.getTable = async (ctx) => {
230
231
  } else {
231
232
  Object.keys(result).forEach((attr) => {
232
233
  obj[attr] = lodash.merge(
233
- app.attributes[model][attr],
234
+ modelAttributes[attr],
234
235
  lodash.omitBy(result[attr], lodash.isNull),
235
236
  app.config[_model].comment && app.config[_model].comment
236
237
  ? app.config[_model].comment[attr]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "9.0.4",
3
+ "version": "9.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {