pangea-server 1.0.49 → 1.0.51
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.
|
@@ -39,9 +39,9 @@ export declare class Db {
|
|
|
39
39
|
constructor(tx: Tx);
|
|
40
40
|
findOneOrNull<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM | null>;
|
|
41
41
|
findOne<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM>;
|
|
42
|
-
|
|
42
|
+
findMany<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyPagedOptions<BM>): Promise<BM[]>;
|
|
43
43
|
count<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyOptions<BM>): Promise<number>;
|
|
44
|
-
|
|
44
|
+
findManyWithCount<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyPagedOptions<BM>): Promise<{
|
|
45
45
|
instances: BM[];
|
|
46
46
|
totalCount: number;
|
|
47
47
|
}>;
|
|
@@ -26,7 +26,7 @@ class Db {
|
|
|
26
26
|
}
|
|
27
27
|
return scopedModel.findOne({
|
|
28
28
|
...baseOptions,
|
|
29
|
-
...getIncludeAndWhere(model, include, filters),
|
|
29
|
+
...getIncludeAndWhere(model, include, undefined, filters),
|
|
30
30
|
order: getFinalOrder(order),
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -36,7 +36,7 @@ class Db {
|
|
|
36
36
|
helpers_1.AppError.ThrowEntityNotFound();
|
|
37
37
|
return instance;
|
|
38
38
|
}
|
|
39
|
-
async
|
|
39
|
+
async findMany(model, options = {}) {
|
|
40
40
|
const baseOptions = this.__getFindManyBaseOptions(model, options);
|
|
41
41
|
const { page, pageSize } = options;
|
|
42
42
|
if (page && pageSize) {
|
|
@@ -57,16 +57,16 @@ class Db {
|
|
|
57
57
|
const baseOptions = this.__getFindManyBaseOptions(model, options);
|
|
58
58
|
return model.count({ ...baseOptions, col: 'id', distinct: true });
|
|
59
59
|
}
|
|
60
|
-
async
|
|
60
|
+
async findManyWithCount(model, options = {}) {
|
|
61
61
|
const { page, pageSize } = options;
|
|
62
62
|
if (page && pageSize) {
|
|
63
63
|
const [instances, totalCount] = await Promise.all([
|
|
64
|
-
this.
|
|
64
|
+
this.findMany(model, options),
|
|
65
65
|
this.count(model, options),
|
|
66
66
|
]);
|
|
67
67
|
return { instances, totalCount };
|
|
68
68
|
}
|
|
69
|
-
const instances = await this.
|
|
69
|
+
const instances = await this.findMany(model, options);
|
|
70
70
|
return { instances, totalCount: instances.length };
|
|
71
71
|
}
|
|
72
72
|
__getFindManyBaseOptions(model, options = {}) {
|
|
@@ -86,7 +86,7 @@ class Db {
|
|
|
86
86
|
const deletedAtWhere = paranoid === 'deleted' ? { deletedAt: { [_1.Ops.not]: null } } : {};
|
|
87
87
|
return {
|
|
88
88
|
attributes: getFinalAttributes(attributes),
|
|
89
|
-
...getIncludeAndWhere(model, include, { ...where, ...searchWhere, ...deletedAtWhere }),
|
|
89
|
+
...getIncludeAndWhere(model, include, { withoutAttributes: !!attributes }, { ...where, ...searchWhere, ...deletedAtWhere }),
|
|
90
90
|
...(group && { group: group.map(pangea_helpers_1.camelToSnake) }),
|
|
91
91
|
order: [...getFinalOrder(order), ...(!group ? [['createdAt', 'DESC']] : [])],
|
|
92
92
|
paranoid: paranoid === 'active',
|
|
@@ -227,7 +227,7 @@ function convertWhereKeys(obj) {
|
|
|
227
227
|
}
|
|
228
228
|
return obj;
|
|
229
229
|
}
|
|
230
|
-
function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
|
|
230
|
+
function getIncludeAndWhere(model, includeItems, config = {}, where, relDepth = new Map()) {
|
|
231
231
|
const includeOptions = [];
|
|
232
232
|
const cleanWhere = { ...where };
|
|
233
233
|
for (const [relName, rel] of Object.entries(model.Relations)) {
|
|
@@ -247,9 +247,10 @@ function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
|
|
|
247
247
|
includeOptions.push({
|
|
248
248
|
model: relModel,
|
|
249
249
|
as: relName,
|
|
250
|
+
attributes: !config.withoutAttributes ? undefined : [],
|
|
250
251
|
required: rel.required,
|
|
251
252
|
paranoid: rel.paranoid,
|
|
252
|
-
...getIncludeAndWhere(relModel, nestedIncludeItems, relWhere, newRelDepth),
|
|
253
|
+
...getIncludeAndWhere(relModel, nestedIncludeItems, config, relWhere, newRelDepth),
|
|
253
254
|
});
|
|
254
255
|
}
|
|
255
256
|
return {
|