pangea-server 1.0.64 → 1.0.66

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.
@@ -74,15 +74,16 @@ class Db {
74
74
  return { instances, totalCount: instances.length };
75
75
  }
76
76
  async aggregateMany(model, config, options = {}) {
77
- const baseOptions = this.__getFindManyBaseOptions(model, options);
77
+ const { attributes, group } = config;
78
+ const baseOptions = this.__getFindManyBaseOptions(model, { ...options, attributes });
78
79
  return model.findAll({
79
80
  ...baseOptions,
80
- attributes: getFinalAttributes(model, config.attributes),
81
- ...(config.group && { group: config.group.map((field) => formatField(model.name, field)) }),
81
+ attributes: getFinalAttributes(model, attributes),
82
+ ...(group && { group: group.map((field) => formatField(model.name, field)) }),
82
83
  });
83
84
  }
84
85
  __getFindManyBaseOptions(model, options = {}) {
85
- const { where, searchFields, search, order, paranoid = true } = options;
86
+ const { attributes, where, searchFields, search, order, paranoid = true } = options;
86
87
  let searchWhere;
87
88
  if (searchFields?.length && search) {
88
89
  const searchWords = search.split(/\s+/).filter(Boolean);
@@ -96,7 +97,7 @@ class Db {
96
97
  };
97
98
  }
98
99
  return {
99
- ...getInclude(model, { where: { ...where, ...searchWhere } }),
100
+ ...getInclude(model, { attributes, where: { ...where, ...searchWhere } }),
100
101
  order: getFinalOrder(order),
101
102
  paranoid,
102
103
  subQuery: false,
@@ -252,8 +253,6 @@ function getInclude(model, config = {}, relDepth = new Map()) {
252
253
  const maxDepth = rel.joinDepth;
253
254
  if (currentDepth >= maxDepth)
254
255
  continue;
255
- if (!rel.eager)
256
- continue;
257
256
  const relWhere = cleanWhere[relName];
258
257
  delete cleanWhere[relName];
259
258
  const newRelDepth = new Map(relDepth);
@@ -1,6 +1,5 @@
1
1
  import type { GetModelFn } from '../database.types';
2
2
  type RelationOptions = {
3
- eager?: boolean;
4
3
  required?: boolean;
5
4
  paranoid?: boolean;
6
5
  joinDepth?: number;
@@ -35,8 +35,8 @@ function getRelation(relationFn) {
35
35
  const { foreignKey, ...relOptions } = options;
36
36
  relationFn(getModelFn, { as: propertyName, ...(foreignKey && { foreignKey }) })(target, propertyName);
37
37
  const model = target.constructor;
38
- const { eager = relationFn !== seq.HasMany, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
39
- model.AddRelation(propertyName, { getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
38
+ const { required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
39
+ model.AddRelation(propertyName, { getModelFn, required, paranoid, joinDepth, ...restOptions });
40
40
  };
41
41
  };
42
42
  }
@@ -7,7 +7,6 @@ type Column = {
7
7
  type Columns = Record<string, Column>;
8
8
  type Relation = {
9
9
  getModelFn: GetModelFn;
10
- eager: boolean;
11
10
  required: boolean;
12
11
  paranoid: boolean;
13
12
  joinDepth: number;
@@ -13,16 +13,22 @@ const validate_request_1 = require("../validator/validate-request");
13
13
  function callController(controller, validate, authConfig) {
14
14
  const { authMap, authCtor, accessToken } = authConfig;
15
15
  return async function (req, res) {
16
+ console.log('a');
16
17
  const headers = req.headers;
17
18
  const inputs = (0, validate_request_1.validateRequest)(validate, req);
18
19
  const ctx = { headers, ...inputs, file: req.file, files: req.files };
20
+ console.log('bb');
19
21
  const tx = await (0, database_1.getDbClient)().transaction();
20
22
  const db = new database_1.Db(tx);
23
+ console.log('ccc');
21
24
  try {
22
25
  const authUsers = await (0, authentication_1.getUsersFromToken)(headers.authorization, db, accessToken, authMap);
23
26
  const auth = new authCtor(authUsers);
27
+ console.log('dddd');
24
28
  const result = await controller(ctx, db, auth);
29
+ console.log('eeeee');
25
30
  await tx.commit();
31
+ console.log('ffff');
26
32
  let data = result;
27
33
  let totalCount;
28
34
  if (hasInstancesAndTotalCount(result)) {
@@ -34,9 +40,11 @@ function callController(controller, validate, authConfig) {
34
40
  totalCount: typeof totalCount === 'number' ? totalCount : null,
35
41
  successCode: (0, pangea_helpers_1.camelToUpperSnake)(controller.name),
36
42
  };
43
+ console.log('ggggggg');
37
44
  res.status(http_status_codes_1.StatusCodes.OK).json(jsonBody);
38
45
  }
39
46
  catch (err) {
47
+ console.log('error');
40
48
  await tx.rollback();
41
49
  throw err;
42
50
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.64",
4
+ "version": "1.0.66",
5
5
  "files": [
6
6
  "dist"
7
7
  ],