pangea-server 3.3.147 → 3.3.149

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.
@@ -22,11 +22,16 @@ class Db {
22
22
  instance = await scopedModel.findByPk(filters, { ...baseOptions, ...getInclude(model) });
23
23
  }
24
24
  else {
25
- instance = await scopedModel.findOne({
25
+ const idRow = await scopedModel.findOne({
26
26
  ...baseOptions,
27
- ...getInclude(model, { where: filters }),
27
+ ...getInclude(model, { idsOnly: true, where: filters }),
28
+ attributes: [[(0, sequelize_1.col)(`${model.name}.id`), 'id']],
28
29
  order: getFinalOrder(order),
30
+ raw: true,
29
31
  });
32
+ if (!idRow)
33
+ return null;
34
+ instance = await scopedModel.findByPk(idRow.id, { ...baseOptions, ...getInclude(model, { where: filters }) });
30
35
  }
31
36
  if (!instance)
32
37
  return null;
@@ -57,7 +62,7 @@ class Db {
57
62
  let instances;
58
63
  if (page && pageSize) {
59
64
  const idRows = await model.findAll({
60
- ...baseOptions,
65
+ ...this.__getFindManyBaseOptions(model, { ...options, idsOnly: true }),
61
66
  attributes: [[(0, sequelize_1.col)(`${model.name}.id`), 'id']],
62
67
  group: [`${model.name}.id`],
63
68
  raw: true,
@@ -109,7 +114,7 @@ class Db {
109
114
  return result;
110
115
  }
111
116
  __getFindManyBaseOptions(model, options = {}) {
112
- const { attributes, where, searchFields, search, order, paranoid = true } = options;
117
+ const { attributes, idsOnly, where, searchFields, search, order, paranoid = true } = options;
113
118
  let searchWhere;
114
119
  if (searchFields?.length && search) {
115
120
  const searchWords = search.split(/\s+/).filter(Boolean);
@@ -123,7 +128,7 @@ class Db {
123
128
  };
124
129
  }
125
130
  return {
126
- ...getInclude(model, { attributes, where: { ...where, ...searchWhere } }),
131
+ ...getInclude(model, { attributes, idsOnly, where: { ...where, ...searchWhere } }),
127
132
  order: getFinalOrder(order),
128
133
  paranoid,
129
134
  subQuery: false,
@@ -285,7 +290,7 @@ function getInclude(model, config = {}, relDepth = new Map()) {
285
290
  includeOptions.push({
286
291
  model: relModel,
287
292
  as: relName,
288
- attributes: !config.attributes ? undefined : [],
293
+ attributes: config.attributes || config.idsOnly ? [] : undefined,
289
294
  required: rel.required,
290
295
  paranoid: rel.paranoid,
291
296
  ...getInclude(relModel, { ...config, where: relWhere }, newRelDepth),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.147",
4
+ "version": "3.3.149",
5
5
  "engines": {
6
6
  "node": "22.14.0"
7
7
  },