@aldb2b/common 1.0.102 → 1.0.105
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/build/db/CustomModel.d.ts +4 -4
- package/build/db/CustomModel.js +7 -7
- package/build/db/MongooseBase.d.ts +37 -37
- package/build/db/MongooseBase.js +321 -321
- package/build/db/aggregate/AggregateConvertor.d.ts +23 -23
- package/build/db/aggregate/AggregateConvertor.js +211 -211
- package/build/db/aggregate/createAggregateResponse.d.ts +2 -2
- package/build/db/aggregate/createAggregateResponse.js +49 -49
- package/build/db/mongoose-find-options.d.ts +12 -12
- package/build/db/mongoose-find-options.js +67 -67
- package/build/decorators/get-event-id-decorator.d.ts +1 -1
- package/build/decorators/get-event-id-decorator.js +9 -9
- package/build/decorators/get-user-decorator.d.ts +1 -1
- package/build/decorators/get-user-decorator.js +12 -12
- package/build/events/attendee-contact.interface.d.ts +10 -10
- package/build/events/attendee-contact.interface.js +2 -2
- package/build/events/authorize-user.interface.d.ts +13 -13
- package/build/events/authorize-user.interface.js +2 -2
- package/build/events/campaign-users.interface.d.ts +11 -11
- package/build/events/campaign-users.interface.js +2 -2
- package/build/events/compute-calendar.interface.d.ts +14 -14
- package/build/events/compute-calendar.interface.js +2 -2
- package/build/events/contacts-by-search.interface.d.ts +10 -10
- package/build/events/contacts-by-search.interface.js +2 -2
- package/build/events/create-company-setting.interface.d.ts +18 -16
- package/build/events/create-company-setting.interface.js +2 -2
- package/build/events/create-company.interface.d.ts +15 -13
- package/build/events/create-company.interface.js +2 -2
- package/build/events/create-contact.interface.d.ts +17 -15
- package/build/events/create-contact.interface.js +2 -2
- package/build/events/data-by-search.interface.d.ts +10 -10
- package/build/events/data-by-search.interface.js +2 -2
- package/build/events/edit-list-users.interface.d.ts +10 -10
- package/build/events/edit-list-users.interface.js +2 -2
- package/build/events/email-specs.interface.d.ts +18 -18
- package/build/events/email-specs.interface.js +2 -2
- package/build/events/get-companies.interface.d.ts +10 -10
- package/build/events/get-companies.interface.js +2 -2
- package/build/events/get-event.interface.d.ts +10 -10
- package/build/events/get-event.interface.js +2 -2
- package/build/events/get-unavailable-by-user.interface.d.ts +13 -13
- package/build/events/get-unavailable-by-user.interface.js +2 -2
- package/build/events/get-user-by-id.interface.d.ts +10 -10
- package/build/events/get-user-by-id.interface.js +2 -2
- package/build/events/groups-by-company.interface.d.ts +13 -13
- package/build/events/groups-by-company.interface.js +2 -2
- package/build/events/groups-by-ids.interface.d.ts +10 -10
- package/build/events/groups-by-ids.interface.js +2 -2
- package/build/events/manage-asseccibillity.interface.d.ts +13 -13
- package/build/events/manage-asseccibillity.interface.js +2 -2
- package/build/events/meeting-count-by-company.interface.d.ts +10 -10
- package/build/events/meeting-count-by-company.interface.js +2 -2
- package/build/events/meeting-count-by-user.interface.d.ts +10 -10
- package/build/events/meeting-count-by-user.interface.js +2 -2
- package/build/events/meeting-request-created.interface.d.ts +20 -20
- package/build/events/meeting-request-created.interface.js +2 -2
- package/build/events/meeting-requested-users.interface.d.ts +10 -10
- package/build/events/meeting-requested-users.interface.js +2 -2
- package/build/events/send-emails.interface.d.ts +21 -21
- package/build/events/send-emails.interface.js +2 -2
- package/build/events/subjects.d.ts +26 -26
- package/build/events/subjects.js +30 -30
- package/build/events/update-company-setting.interface.d.ts +18 -16
- package/build/events/update-company-setting.interface.js +2 -2
- package/build/events/update-user-event-info.interface.d.ts +17 -17
- package/build/events/update-user-event-info.interface.js +2 -2
- package/build/index.d.ts +75 -71
- package/build/index.js +87 -83
- package/build/index.js.map +1 -1
- package/build/interceptors/response.interceptor.d.ts +6 -6
- package/build/interceptors/response.interceptor.js +30 -30
- package/build/interceptors/serialize.interceptor.d.ts +12 -12
- package/build/interceptors/serialize.interceptor.js +24 -24
- package/build/middlewares/app.middleware.d.ts +6 -6
- package/build/middlewares/app.middleware.js +29 -29
- package/build/middlewares/authorizer.middleware.d.ts +10 -10
- package/build/middlewares/authorizer.middleware.js +102 -102
- package/build/tsconfig.tsbuildinfo +5063 -5019
- package/build/types/analytic-group.interface.d.ts +12 -0
- package/build/types/analytic-group.interface.js +3 -0
- package/build/types/analytic-group.interface.js.map +1 -0
- package/build/types/chat-group.interface.d.ts +4 -0
- package/build/types/{visibility.interface.js → chat-group.interface.js} +3 -3
- package/build/types/chat-group.interface.js.map +1 -0
- package/build/types/{visibility.interface.d.ts → default-visibility.interface.d.ts} +13 -10
- package/build/types/default-visibility.interface.js +3 -0
- package/build/types/default-visibility.interface.js.map +1 -0
- package/build/types/download-presigned-url.interface.d.ts +4 -4
- package/build/types/download-presigned-url.interface.js +2 -2
- package/build/types/group-visibility.interface.d.ts +13 -0
- package/build/types/group-visibility.interface.js +3 -0
- package/build/types/group-visibility.interface.js.map +1 -0
- package/build/types/header-user.interface.d.ts +8 -8
- package/build/types/header-user.interface.js +2 -2
- package/build/types/match-group.interface.d.ts +7 -7
- package/build/types/match-group.interface.js +2 -2
- package/build/types/match.interface.d.ts +6 -6
- package/build/types/match.interface.js +2 -2
- package/build/types/meeting-request-token.interface.d.ts +7 -6
- package/build/types/meeting-request-token.interface.js +2 -2
- package/build/types/meeting-type.enum.d.ts +6 -6
- package/build/types/meeting-type.enum.js +10 -10
- package/build/types/operation-types.d.ts +5 -5
- package/build/types/operation-types.js +9 -9
- package/build/types/read-result.interface.d.ts +5 -5
- package/build/types/read-result.interface.js +2 -2
- package/build/types/update-input-data.interface.d.ts +10 -10
- package/build/types/update-input-data.interface.js +2 -2
- package/build/types/upload-presigned-url.interface.d.ts +4 -4
- package/build/types/upload-presigned-url.interface.js +2 -2
- package/build/types/user-invitations.interface.d.ts +6 -6
- package/build/types/user-invitations.interface.js +2 -2
- package/build/types/user-role.enum.d.ts +7 -7
- package/build/types/user-role.enum.js +11 -11
- package/build/types/user-type.enum.d.ts +5 -5
- package/build/types/user-type.enum.js +9 -9
- package/build/types/visibility-group.interface.d.ts +6 -6
- package/build/types/visibility-group.interface.js +2 -2
- package/build/utils/create-default-directories.d.ts +1 -1
- package/build/utils/create-default-directories.js +23 -23
- package/build/utils/equal-array-object.d.ts +1 -1
- package/build/utils/equal-array-object.js +9 -9
- package/build/utils/equal-object.d.ts +1 -1
- package/build/utils/equal-object.js +8 -8
- package/build/utils/parse-query.d.ts +1 -1
- package/build/utils/parse-query.js +30 -30
- package/build/utils/projection.d.ts +1 -1
- package/build/utils/projection.js +25 -25
- package/build/utils/timezone.d.ts +2 -2
- package/build/utils/timezone.js +14 -14
- package/build/validators/conditional-required.d.ts +2 -2
- package/build/validators/conditional-required.js +23 -23
- package/build/validators/date-validator.d.ts +2 -2
- package/build/validators/date-validator.js +20 -20
- package/build/validators/responses/customizeArrayResponse.d.ts +3 -3
- package/build/validators/responses/customizeArrayResponse.js +23 -23
- package/build/validators/responses/error.d.ts +2 -2
- package/build/validators/responses/error.interface.d.ts +4 -4
- package/build/validators/responses/error.interface.js +2 -2
- package/build/validators/responses/error.js +28 -28
- package/build/validators/responses/response-option.interface.d.ts +7 -7
- package/build/validators/responses/response-option.interface.js +2 -2
- package/build/validators/responses/succes-result.interface.d.ts +10 -10
- package/build/validators/responses/succes-result.interface.js +2 -2
- package/build/validators/responses/success.d.ts +3 -3
- package/build/validators/responses/success.interface.d.ts +4 -4
- package/build/validators/responses/success.interface.js +2 -2
- package/build/validators/responses/success.js +14 -14
- package/build/validators/validateNewItem.d.ts +1 -1
- package/build/validators/validateNewItem.js +22 -22
- package/build/validators/validateProjection.d.ts +1 -1
- package/build/validators/validateProjection.js +32 -32
- package/build/validators/validateProjectionResult.d.ts +1 -1
- package/build/validators/validateProjectionResult.js +36 -36
- package/build/validators/validateUpdateItem.d.ts +1 -1
- package/build/validators/validateUpdateItem.js +22 -22
- package/package.json +35 -35
- package/build/types/visibility.interface.js.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as mongoose from 'mongoose';
|
|
2
|
-
import { MongooseFindOptions } from '../mongoose-find-options';
|
|
3
|
-
export declare class AggregateConvertor {
|
|
4
|
-
private findDto;
|
|
5
|
-
private populateFields;
|
|
6
|
-
private nonArrayAttributes;
|
|
7
|
-
private aggregates;
|
|
8
|
-
constructor(findDto: MongooseFindOptions, populateFields: object, nonArrayAttributes?: string[]);
|
|
9
|
-
createAggregate(): mongoose.PipelineStage[];
|
|
10
|
-
private modifyQuery;
|
|
11
|
-
private createLookups;
|
|
12
|
-
private getFieldToPopulate;
|
|
13
|
-
private getPipeLine;
|
|
14
|
-
private getInitialPipeline;
|
|
15
|
-
private getPipelineExpression;
|
|
16
|
-
private createObjectIds;
|
|
17
|
-
private isValidObjectId;
|
|
18
|
-
private hasLookupIndex;
|
|
19
|
-
private addProjection;
|
|
20
|
-
private createParameters;
|
|
21
|
-
private getSort;
|
|
22
|
-
private getLimit;
|
|
23
|
-
}
|
|
1
|
+
import * as mongoose from 'mongoose';
|
|
2
|
+
import { MongooseFindOptions } from '../mongoose-find-options';
|
|
3
|
+
export declare class AggregateConvertor {
|
|
4
|
+
private findDto;
|
|
5
|
+
private populateFields;
|
|
6
|
+
private nonArrayAttributes;
|
|
7
|
+
private aggregates;
|
|
8
|
+
constructor(findDto: MongooseFindOptions, populateFields: object, nonArrayAttributes?: string[]);
|
|
9
|
+
createAggregate(): mongoose.PipelineStage[];
|
|
10
|
+
private modifyQuery;
|
|
11
|
+
private createLookups;
|
|
12
|
+
private getFieldToPopulate;
|
|
13
|
+
private getPipeLine;
|
|
14
|
+
private getInitialPipeline;
|
|
15
|
+
private getPipelineExpression;
|
|
16
|
+
private createObjectIds;
|
|
17
|
+
private isValidObjectId;
|
|
18
|
+
private hasLookupIndex;
|
|
19
|
+
private addProjection;
|
|
20
|
+
private createParameters;
|
|
21
|
+
private getSort;
|
|
22
|
+
private getLimit;
|
|
23
|
+
}
|
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AggregateConvertor = void 0;
|
|
4
|
-
const mongoose = require("mongoose");
|
|
5
|
-
const moment = require("moment");
|
|
6
|
-
const ObjectId = mongoose.Types.ObjectId;
|
|
7
|
-
class AggregateConvertor {
|
|
8
|
-
constructor(findDto, populateFields, nonArrayAttributes = []) {
|
|
9
|
-
this.findDto = findDto;
|
|
10
|
-
this.populateFields = populateFields;
|
|
11
|
-
this.nonArrayAttributes = nonArrayAttributes;
|
|
12
|
-
this.aggregates = [{ $match: {} }];
|
|
13
|
-
}
|
|
14
|
-
createAggregate() {
|
|
15
|
-
this.modifyQuery();
|
|
16
|
-
this.createLookups();
|
|
17
|
-
this.createObjectIds(this.findDto);
|
|
18
|
-
this.addProjection();
|
|
19
|
-
this.createParameters();
|
|
20
|
-
return this.aggregates;
|
|
21
|
-
}
|
|
22
|
-
modifyQuery() {
|
|
23
|
-
if (this.findDto &&
|
|
24
|
-
Array.isArray(this.findDto.populates) &&
|
|
25
|
-
this.findDto.populates.length > 0) {
|
|
26
|
-
this.findDto.populates = this.findDto.populates.map(item => {
|
|
27
|
-
try {
|
|
28
|
-
return JSON.parse(item);
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
return item;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (this.findDto.query) {
|
|
36
|
-
try {
|
|
37
|
-
this.findDto.query = JSON.parse(this.findDto.query);
|
|
38
|
-
}
|
|
39
|
-
catch (err) { }
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
createLookups() {
|
|
43
|
-
const lookUps = [];
|
|
44
|
-
if (this.findDto.needPopulate &&
|
|
45
|
-
Array.isArray(this.findDto.populates) &&
|
|
46
|
-
this.findDto.populates.length) {
|
|
47
|
-
this.findDto.populates.forEach(item => {
|
|
48
|
-
const itemType = typeof item;
|
|
49
|
-
const fieldToPopulate = this.getFieldToPopulate(item, itemType);
|
|
50
|
-
const pipeLine = this.getPipeLine(item, itemType, fieldToPopulate);
|
|
51
|
-
const lookUp = {
|
|
52
|
-
$lookup: {
|
|
53
|
-
from: this.populateFields[fieldToPopulate],
|
|
54
|
-
localField: fieldToPopulate,
|
|
55
|
-
foreignField: '_id',
|
|
56
|
-
as: `${fieldToPopulate}`,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
if (Array.isArray(lookUp.$lookup.from)) {
|
|
60
|
-
for (let [index, value] of lookUp.$lookup.from.entries()) {
|
|
61
|
-
let finalLookup = Object.assign({}, lookUp);
|
|
62
|
-
finalLookup.$lookup.from = value;
|
|
63
|
-
finalLookup.$lookup.as = 'record' + index;
|
|
64
|
-
lookUps.push({ $lookup: Object.assign({}, finalLookup.$lookup) });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
lookUps.push(lookUp);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
this.aggregates.push(...lookUps);
|
|
73
|
-
}
|
|
74
|
-
getFieldToPopulate(item, itemType) {
|
|
75
|
-
return itemType === 'object'
|
|
76
|
-
? item.path
|
|
77
|
-
: itemType === 'string'
|
|
78
|
-
? item
|
|
79
|
-
: null;
|
|
80
|
-
}
|
|
81
|
-
getPipeLine(item, itemType, fieldToPopulate) {
|
|
82
|
-
const projection = itemType === 'object' && item.select
|
|
83
|
-
? item.select.trim().split(/\s+/)
|
|
84
|
-
: null;
|
|
85
|
-
const pipeLine = this.getInitialPipeline(fieldToPopulate);
|
|
86
|
-
if (projection) {
|
|
87
|
-
const selectObject = projection.reduce((obj, item) => {
|
|
88
|
-
return Object.assign(Object.assign({}, obj), { [item]: 1 });
|
|
89
|
-
}, {});
|
|
90
|
-
const projectionObj = { $project: selectObject };
|
|
91
|
-
pipeLine.push(projectionObj);
|
|
92
|
-
}
|
|
93
|
-
return pipeLine;
|
|
94
|
-
}
|
|
95
|
-
getInitialPipeline(fieldToPopulate) {
|
|
96
|
-
return [
|
|
97
|
-
{
|
|
98
|
-
$match: {
|
|
99
|
-
$expr: {
|
|
100
|
-
[`${this.getPipelineExpression(fieldToPopulate)}`]: [
|
|
101
|
-
'$_id',
|
|
102
|
-
'$$field_id',
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
getPipelineExpression(fieldToPopulate) {
|
|
110
|
-
return this.nonArrayAttributes.includes(fieldToPopulate) ? '$eq' : '$in';
|
|
111
|
-
}
|
|
112
|
-
createObjectIds(query) {
|
|
113
|
-
for (const item in query) {
|
|
114
|
-
if (this.isValidObjectId(query[item]) && this.hasLookupIndex(item)) {
|
|
115
|
-
const moduleName = `${item}._id`;
|
|
116
|
-
query[moduleName] = new ObjectId(query[item]);
|
|
117
|
-
delete query[item];
|
|
118
|
-
}
|
|
119
|
-
else if (typeof query[item] == 'object' &&
|
|
120
|
-
!this.isValidObjectId(query[item])) {
|
|
121
|
-
this.createObjectIds(query[item]);
|
|
122
|
-
}
|
|
123
|
-
else if (this.isValidObjectId(query[item]) &&
|
|
124
|
-
!this.hasLookupIndex(item)) {
|
|
125
|
-
query[item] = new ObjectId(query[item]);
|
|
126
|
-
}
|
|
127
|
-
else if (moment(query[item], moment.ISO_8601, true).isValid() &&
|
|
128
|
-
String(query[item]).includes('-')) {
|
|
129
|
-
query[item] = new Date(query[item]);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (query.query) {
|
|
133
|
-
this.aggregates.push({ $match: query.query });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
isValidObjectId(id) {
|
|
137
|
-
if (!ObjectId.isValid(id)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const newId = new ObjectId(id);
|
|
142
|
-
return String(newId) === id;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
hasLookupIndex(field) {
|
|
146
|
-
const jobIndex = this.aggregates.findIndex(aggregate => { var _a; return ((_a = aggregate['$lookup']) === null || _a === void 0 ? void 0 : _a.as) == field; });
|
|
147
|
-
return jobIndex !== -1;
|
|
148
|
-
}
|
|
149
|
-
addProjection() {
|
|
150
|
-
if (this.findDto.necessaryProjectionArray) {
|
|
151
|
-
const projection = { $project: {} };
|
|
152
|
-
this.findDto.necessaryProjectionArray.forEach(item => {
|
|
153
|
-
projection.$project[item] = 1;
|
|
154
|
-
});
|
|
155
|
-
this.aggregates.push(projection);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
createParameters() {
|
|
159
|
-
const parameters = {
|
|
160
|
-
$facet: {
|
|
161
|
-
data: [],
|
|
162
|
-
total: [],
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
if (this.findDto.sort) {
|
|
166
|
-
parameters.$facet.data.push(this.getSort(this.findDto.sort));
|
|
167
|
-
}
|
|
168
|
-
if (this.findDto.hasTotal) {
|
|
169
|
-
parameters.$facet.total.push({ $count: 'total' });
|
|
170
|
-
}
|
|
171
|
-
if (this.findDto.skip) {
|
|
172
|
-
parameters.$facet.data.push({ $skip: Number(this.findDto.skip) });
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
parameters.$facet.data.push({ $skip: 0 });
|
|
176
|
-
}
|
|
177
|
-
parameters.$facet.data.push({ $limit: this.getLimit(this.findDto.limit) });
|
|
178
|
-
if (!parameters.$facet.total.length) {
|
|
179
|
-
delete parameters.$facet.total;
|
|
180
|
-
}
|
|
181
|
-
this.aggregates.push(parameters);
|
|
182
|
-
}
|
|
183
|
-
getSort(sort) {
|
|
184
|
-
let sortObject = {};
|
|
185
|
-
try {
|
|
186
|
-
sortObject = JSON.parse(sort);
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
const sortArray = sort.trim().split(/\s+/);
|
|
190
|
-
sortArray.forEach(item => {
|
|
191
|
-
if (item.charAt(0) === '-') {
|
|
192
|
-
sortObject[item.substring(1)] = -1;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
sortObject[item] = 1;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
return { $sort: sortObject };
|
|
200
|
-
}
|
|
201
|
-
getLimit(limit) {
|
|
202
|
-
if (limit) {
|
|
203
|
-
const castedLimit = Number(limit);
|
|
204
|
-
return castedLimit > 100 ? 100 : castedLimit;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
return 100;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.AggregateConvertor = AggregateConvertor;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateConvertor = void 0;
|
|
4
|
+
const mongoose = require("mongoose");
|
|
5
|
+
const moment = require("moment");
|
|
6
|
+
const ObjectId = mongoose.Types.ObjectId;
|
|
7
|
+
class AggregateConvertor {
|
|
8
|
+
constructor(findDto, populateFields, nonArrayAttributes = []) {
|
|
9
|
+
this.findDto = findDto;
|
|
10
|
+
this.populateFields = populateFields;
|
|
11
|
+
this.nonArrayAttributes = nonArrayAttributes;
|
|
12
|
+
this.aggregates = [{ $match: {} }];
|
|
13
|
+
}
|
|
14
|
+
createAggregate() {
|
|
15
|
+
this.modifyQuery();
|
|
16
|
+
this.createLookups();
|
|
17
|
+
this.createObjectIds(this.findDto);
|
|
18
|
+
this.addProjection();
|
|
19
|
+
this.createParameters();
|
|
20
|
+
return this.aggregates;
|
|
21
|
+
}
|
|
22
|
+
modifyQuery() {
|
|
23
|
+
if (this.findDto &&
|
|
24
|
+
Array.isArray(this.findDto.populates) &&
|
|
25
|
+
this.findDto.populates.length > 0) {
|
|
26
|
+
this.findDto.populates = this.findDto.populates.map(item => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(item);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (this.findDto.query) {
|
|
36
|
+
try {
|
|
37
|
+
this.findDto.query = JSON.parse(this.findDto.query);
|
|
38
|
+
}
|
|
39
|
+
catch (err) { }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
createLookups() {
|
|
43
|
+
const lookUps = [];
|
|
44
|
+
if (this.findDto.needPopulate &&
|
|
45
|
+
Array.isArray(this.findDto.populates) &&
|
|
46
|
+
this.findDto.populates.length) {
|
|
47
|
+
this.findDto.populates.forEach(item => {
|
|
48
|
+
const itemType = typeof item;
|
|
49
|
+
const fieldToPopulate = this.getFieldToPopulate(item, itemType);
|
|
50
|
+
const pipeLine = this.getPipeLine(item, itemType, fieldToPopulate);
|
|
51
|
+
const lookUp = {
|
|
52
|
+
$lookup: {
|
|
53
|
+
from: this.populateFields[fieldToPopulate],
|
|
54
|
+
localField: fieldToPopulate,
|
|
55
|
+
foreignField: '_id',
|
|
56
|
+
as: `${fieldToPopulate}`,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
if (Array.isArray(lookUp.$lookup.from)) {
|
|
60
|
+
for (let [index, value] of lookUp.$lookup.from.entries()) {
|
|
61
|
+
let finalLookup = Object.assign({}, lookUp);
|
|
62
|
+
finalLookup.$lookup.from = value;
|
|
63
|
+
finalLookup.$lookup.as = 'record' + index;
|
|
64
|
+
lookUps.push({ $lookup: Object.assign({}, finalLookup.$lookup) });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
lookUps.push(lookUp);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
this.aggregates.push(...lookUps);
|
|
73
|
+
}
|
|
74
|
+
getFieldToPopulate(item, itemType) {
|
|
75
|
+
return itemType === 'object'
|
|
76
|
+
? item.path
|
|
77
|
+
: itemType === 'string'
|
|
78
|
+
? item
|
|
79
|
+
: null;
|
|
80
|
+
}
|
|
81
|
+
getPipeLine(item, itemType, fieldToPopulate) {
|
|
82
|
+
const projection = itemType === 'object' && item.select
|
|
83
|
+
? item.select.trim().split(/\s+/)
|
|
84
|
+
: null;
|
|
85
|
+
const pipeLine = this.getInitialPipeline(fieldToPopulate);
|
|
86
|
+
if (projection) {
|
|
87
|
+
const selectObject = projection.reduce((obj, item) => {
|
|
88
|
+
return Object.assign(Object.assign({}, obj), { [item]: 1 });
|
|
89
|
+
}, {});
|
|
90
|
+
const projectionObj = { $project: selectObject };
|
|
91
|
+
pipeLine.push(projectionObj);
|
|
92
|
+
}
|
|
93
|
+
return pipeLine;
|
|
94
|
+
}
|
|
95
|
+
getInitialPipeline(fieldToPopulate) {
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
$match: {
|
|
99
|
+
$expr: {
|
|
100
|
+
[`${this.getPipelineExpression(fieldToPopulate)}`]: [
|
|
101
|
+
'$_id',
|
|
102
|
+
'$$field_id',
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
getPipelineExpression(fieldToPopulate) {
|
|
110
|
+
return this.nonArrayAttributes.includes(fieldToPopulate) ? '$eq' : '$in';
|
|
111
|
+
}
|
|
112
|
+
createObjectIds(query) {
|
|
113
|
+
for (const item in query) {
|
|
114
|
+
if (this.isValidObjectId(query[item]) && this.hasLookupIndex(item)) {
|
|
115
|
+
const moduleName = `${item}._id`;
|
|
116
|
+
query[moduleName] = new ObjectId(query[item]);
|
|
117
|
+
delete query[item];
|
|
118
|
+
}
|
|
119
|
+
else if (typeof query[item] == 'object' &&
|
|
120
|
+
!this.isValidObjectId(query[item])) {
|
|
121
|
+
this.createObjectIds(query[item]);
|
|
122
|
+
}
|
|
123
|
+
else if (this.isValidObjectId(query[item]) &&
|
|
124
|
+
!this.hasLookupIndex(item)) {
|
|
125
|
+
query[item] = new ObjectId(query[item]);
|
|
126
|
+
}
|
|
127
|
+
else if (moment(query[item], moment.ISO_8601, true).isValid() &&
|
|
128
|
+
String(query[item]).includes('-')) {
|
|
129
|
+
query[item] = new Date(query[item]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (query.query) {
|
|
133
|
+
this.aggregates.push({ $match: query.query });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
isValidObjectId(id) {
|
|
137
|
+
if (!ObjectId.isValid(id)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const newId = new ObjectId(id);
|
|
142
|
+
return String(newId) === id;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
hasLookupIndex(field) {
|
|
146
|
+
const jobIndex = this.aggregates.findIndex(aggregate => { var _a; return ((_a = aggregate['$lookup']) === null || _a === void 0 ? void 0 : _a.as) == field; });
|
|
147
|
+
return jobIndex !== -1;
|
|
148
|
+
}
|
|
149
|
+
addProjection() {
|
|
150
|
+
if (this.findDto.necessaryProjectionArray) {
|
|
151
|
+
const projection = { $project: {} };
|
|
152
|
+
this.findDto.necessaryProjectionArray.forEach(item => {
|
|
153
|
+
projection.$project[item] = 1;
|
|
154
|
+
});
|
|
155
|
+
this.aggregates.push(projection);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
createParameters() {
|
|
159
|
+
const parameters = {
|
|
160
|
+
$facet: {
|
|
161
|
+
data: [],
|
|
162
|
+
total: [],
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
if (this.findDto.sort) {
|
|
166
|
+
parameters.$facet.data.push(this.getSort(this.findDto.sort));
|
|
167
|
+
}
|
|
168
|
+
if (this.findDto.hasTotal) {
|
|
169
|
+
parameters.$facet.total.push({ $count: 'total' });
|
|
170
|
+
}
|
|
171
|
+
if (this.findDto.skip) {
|
|
172
|
+
parameters.$facet.data.push({ $skip: Number(this.findDto.skip) });
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
parameters.$facet.data.push({ $skip: 0 });
|
|
176
|
+
}
|
|
177
|
+
parameters.$facet.data.push({ $limit: this.getLimit(this.findDto.limit) });
|
|
178
|
+
if (!parameters.$facet.total.length) {
|
|
179
|
+
delete parameters.$facet.total;
|
|
180
|
+
}
|
|
181
|
+
this.aggregates.push(parameters);
|
|
182
|
+
}
|
|
183
|
+
getSort(sort) {
|
|
184
|
+
let sortObject = {};
|
|
185
|
+
try {
|
|
186
|
+
sortObject = JSON.parse(sort);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const sortArray = sort.trim().split(/\s+/);
|
|
190
|
+
sortArray.forEach(item => {
|
|
191
|
+
if (item.charAt(0) === '-') {
|
|
192
|
+
sortObject[item.substring(1)] = -1;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
sortObject[item] = 1;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return { $sort: sortObject };
|
|
200
|
+
}
|
|
201
|
+
getLimit(limit) {
|
|
202
|
+
if (limit) {
|
|
203
|
+
const castedLimit = Number(limit);
|
|
204
|
+
return castedLimit > 100 ? 100 : castedLimit;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
return 100;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.AggregateConvertor = AggregateConvertor;
|
|
212
212
|
//# sourceMappingURL=AggregateConvertor.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MongooseFindOptions } from '../mongoose-find-options';
|
|
2
|
-
export declare function createAggregateResponse(query: MongooseFindOptions, queryResult: any, nonArrayAttributes?: string[]): any;
|
|
1
|
+
import { MongooseFindOptions } from '../mongoose-find-options';
|
|
2
|
+
export declare function createAggregateResponse(query: MongooseFindOptions, queryResult: any, nonArrayAttributes?: string[]): any;
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAggregateResponse = void 0;
|
|
4
|
-
const modifyResponse = (data, nonArrayAttributes) => {
|
|
5
|
-
return data.map(item => {
|
|
6
|
-
nonArrayAttributes.forEach(attr => {
|
|
7
|
-
if (item[attr] && Array.isArray(item[attr]) && item[attr].length) {
|
|
8
|
-
item[attr] = item[attr][0];
|
|
9
|
-
}
|
|
10
|
-
else if (item[attr] && Array.isArray(item[attr])) {
|
|
11
|
-
item[attr] = null;
|
|
12
|
-
}
|
|
13
|
-
return item;
|
|
14
|
-
});
|
|
15
|
-
return item;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
function createAggregateResponse(query, queryResult, nonArrayAttributes = []) {
|
|
19
|
-
var _a, _b, _c, _d;
|
|
20
|
-
const createResponse = {
|
|
21
|
-
data: ((_b = (_a = queryResult[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length)
|
|
22
|
-
? modifyResponse(queryResult[0].data, nonArrayAttributes)
|
|
23
|
-
: [],
|
|
24
|
-
};
|
|
25
|
-
if (query.skip) {
|
|
26
|
-
createResponse.skip = Number(query.skip);
|
|
27
|
-
}
|
|
28
|
-
if (query.limit) {
|
|
29
|
-
createResponse.limit = Number(query.limit);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
createResponse.limit = 100;
|
|
33
|
-
}
|
|
34
|
-
if (query.hasTotal) {
|
|
35
|
-
createResponse.hasTotal = true;
|
|
36
|
-
createResponse.total =
|
|
37
|
-
queryResult[0].total && ((_d = (_c = queryResult[0]) === null || _c === void 0 ? void 0 : _c.total[0]) === null || _d === void 0 ? void 0 : _d.total)
|
|
38
|
-
? queryResult[0].total[0].total
|
|
39
|
-
: 0;
|
|
40
|
-
}
|
|
41
|
-
if (createResponse.data.length) {
|
|
42
|
-
createResponse.count = createResponse.data.length;
|
|
43
|
-
}
|
|
44
|
-
if (query.sort) {
|
|
45
|
-
createResponse.sort = query.sort;
|
|
46
|
-
}
|
|
47
|
-
return createResponse;
|
|
48
|
-
}
|
|
49
|
-
exports.createAggregateResponse = createAggregateResponse;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAggregateResponse = void 0;
|
|
4
|
+
const modifyResponse = (data, nonArrayAttributes) => {
|
|
5
|
+
return data.map(item => {
|
|
6
|
+
nonArrayAttributes.forEach(attr => {
|
|
7
|
+
if (item[attr] && Array.isArray(item[attr]) && item[attr].length) {
|
|
8
|
+
item[attr] = item[attr][0];
|
|
9
|
+
}
|
|
10
|
+
else if (item[attr] && Array.isArray(item[attr])) {
|
|
11
|
+
item[attr] = null;
|
|
12
|
+
}
|
|
13
|
+
return item;
|
|
14
|
+
});
|
|
15
|
+
return item;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
function createAggregateResponse(query, queryResult, nonArrayAttributes = []) {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
const createResponse = {
|
|
21
|
+
data: ((_b = (_a = queryResult[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.length)
|
|
22
|
+
? modifyResponse(queryResult[0].data, nonArrayAttributes)
|
|
23
|
+
: [],
|
|
24
|
+
};
|
|
25
|
+
if (query.skip) {
|
|
26
|
+
createResponse.skip = Number(query.skip);
|
|
27
|
+
}
|
|
28
|
+
if (query.limit) {
|
|
29
|
+
createResponse.limit = Number(query.limit);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
createResponse.limit = 100;
|
|
33
|
+
}
|
|
34
|
+
if (query.hasTotal) {
|
|
35
|
+
createResponse.hasTotal = true;
|
|
36
|
+
createResponse.total =
|
|
37
|
+
queryResult[0].total && ((_d = (_c = queryResult[0]) === null || _c === void 0 ? void 0 : _c.total[0]) === null || _d === void 0 ? void 0 : _d.total)
|
|
38
|
+
? queryResult[0].total[0].total
|
|
39
|
+
: 0;
|
|
40
|
+
}
|
|
41
|
+
if (createResponse.data.length) {
|
|
42
|
+
createResponse.count = createResponse.data.length;
|
|
43
|
+
}
|
|
44
|
+
if (query.sort) {
|
|
45
|
+
createResponse.sort = query.sort;
|
|
46
|
+
}
|
|
47
|
+
return createResponse;
|
|
48
|
+
}
|
|
49
|
+
exports.createAggregateResponse = createAggregateResponse;
|
|
50
50
|
//# sourceMappingURL=createAggregateResponse.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare class MongooseFindOptions {
|
|
2
|
-
query?: string | any;
|
|
3
|
-
hasTotal?: string | boolean;
|
|
4
|
-
skip?: number;
|
|
5
|
-
limit?: number;
|
|
6
|
-
sort?: string;
|
|
7
|
-
needPopulate?: string | boolean;
|
|
8
|
-
populates?: string | string[] | object[];
|
|
9
|
-
necessaryProjectionArray?: string[];
|
|
10
|
-
lean?: string | boolean;
|
|
11
|
-
addPresignedURL?: string | boolean;
|
|
12
|
-
}
|
|
1
|
+
export declare class MongooseFindOptions {
|
|
2
|
+
query?: string | any;
|
|
3
|
+
hasTotal?: string | boolean;
|
|
4
|
+
skip?: number;
|
|
5
|
+
limit?: number;
|
|
6
|
+
sort?: string;
|
|
7
|
+
needPopulate?: string | boolean;
|
|
8
|
+
populates?: string | string[] | object[];
|
|
9
|
+
necessaryProjectionArray?: string[];
|
|
10
|
+
lean?: string | boolean;
|
|
11
|
+
addPresignedURL?: string | boolean;
|
|
12
|
+
}
|