pangea-server 1.0.64 → 1.0.65
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
|
|
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,
|
|
81
|
-
...(
|
|
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);
|
|
@@ -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 {
|
|
39
|
-
model.AddRelation(propertyName, { getModelFn,
|
|
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
|
}
|