@provis/provis-common-be-module 2.1.2 → 2.1.3
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/dist/class/main.repository.d.ts +4 -2
- package/dist/class/main.repository.js +50 -9
- package/dist/interface/find.all.count.interface.d.ts +10 -0
- package/dist/interface/find.all.count.interface.js +2 -0
- package/dist/interface/multi.join.interface.d.ts +6 -0
- package/dist/interface/multi.join.interface.js +2 -0
- package/dist/interface/search.conditions.interface.d.ts +8 -0
- package/dist/interface/search.conditions.interface.js +2 -0
- package/dist/interface/summary.field.interface.d.ts +4 -0
- package/dist/interface/summary.field.interface.js +3 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DeepPartial, FindConditions, Repository } from 'typeorm';
|
|
2
2
|
import ISearchQuery from '../interface/search.query.interface';
|
|
3
3
|
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
4
|
+
import IFindAllCount from '../interface/find.all.count.interface';
|
|
5
|
+
import ISummaryField from '../interface/summary.field.interface';
|
|
4
6
|
export declare class MainRepository<T> extends Repository<T> {
|
|
5
7
|
saveRepo(data: DeepPartial<T>): Promise<T>;
|
|
6
8
|
updateRepo(obj: DeepPartial<T>, updated: QueryDeepPartialEntity<T>): Promise<T>;
|
|
@@ -14,8 +16,8 @@ export declare class MainRepository<T> extends Repository<T> {
|
|
|
14
16
|
orderDirection: 'ASC' | 'DESC';
|
|
15
17
|
};
|
|
16
18
|
searchBracket(searchOr: any[], searchValues: (value: any) => Promise<ISearchQuery[]>): Promise<ISearchQuery[][]>;
|
|
17
|
-
summaryField(search: ISearchQuery[], fieldToSum:
|
|
18
|
-
findAllAndCount(search
|
|
19
|
+
summaryField(search: ISearchQuery[], fieldToSum: ISummaryField[], additionalSearchOr?: ISearchQuery[][]): Promise<any>;
|
|
20
|
+
findAllAndCount({ search, additionalSearchOr, relations, sortBy, offset, maxCount, }: IFindAllCount): Promise<[number, T[]]>;
|
|
19
21
|
private applySearchConditions;
|
|
20
22
|
private generateRawCount;
|
|
21
23
|
private generateRawOrder;
|
|
@@ -121,17 +121,26 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
121
121
|
let query = this.createQueryBuilder()
|
|
122
122
|
.select([
|
|
123
123
|
'COUNT(1) AS totalRows',
|
|
124
|
-
...fieldToSum.map((field) => `SUM(${field}) AS "${field.
|
|
124
|
+
...fieldToSum.map((field) => `SUM(${field.columnName}) AS "${field.aliasColumnName || field.columnName}"`),
|
|
125
125
|
]);
|
|
126
|
-
query = this.applySearchConditions(
|
|
126
|
+
query = this.applySearchConditions({
|
|
127
|
+
query,
|
|
128
|
+
search,
|
|
129
|
+
additionalSearchOr,
|
|
130
|
+
});
|
|
127
131
|
return query.getRawOne();
|
|
128
132
|
});
|
|
129
133
|
}
|
|
130
|
-
findAllAndCount(search,
|
|
134
|
+
findAllAndCount({ search, additionalSearchOr, relations, sortBy, offset = 1, maxCount = 50, }) {
|
|
131
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
136
|
const skipItems = ((offset < 1 ? 1 : offset) - 1) * maxCount;
|
|
133
137
|
let query = this.createQueryBuilder().select(this.selectFieldOnFindAllAndCount());
|
|
134
|
-
query = this.applySearchConditions(
|
|
138
|
+
query = this.applySearchConditions({
|
|
139
|
+
query,
|
|
140
|
+
search,
|
|
141
|
+
additionalSearchOr,
|
|
142
|
+
relations,
|
|
143
|
+
});
|
|
135
144
|
const { orderBy, orderDirection } = this.getOrderData(sortBy);
|
|
136
145
|
return [
|
|
137
146
|
yield query.getCount(),
|
|
@@ -143,17 +152,18 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
143
152
|
];
|
|
144
153
|
});
|
|
145
154
|
}
|
|
146
|
-
applySearchConditions(query, search, additionalSearchOr) {
|
|
155
|
+
applySearchConditions({ query, search, additionalSearchOr, relations, }) {
|
|
156
|
+
const modelName = this.modelName();
|
|
147
157
|
if (search && search.length > 0) {
|
|
148
158
|
let index = 0;
|
|
149
159
|
search.forEach((value) => {
|
|
150
160
|
if (value) {
|
|
151
161
|
if (index === 0) {
|
|
152
|
-
query = query.where(`${
|
|
162
|
+
query = query.where(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
153
163
|
index++;
|
|
154
164
|
}
|
|
155
165
|
else {
|
|
156
|
-
query = query.andWhere(`${
|
|
166
|
+
query = query.andWhere(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
});
|
|
@@ -166,11 +176,11 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
166
176
|
group.forEach((value) => {
|
|
167
177
|
if (value) {
|
|
168
178
|
if (index === 0) {
|
|
169
|
-
qb = qb.where(`${
|
|
179
|
+
qb = qb.where(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
170
180
|
index++;
|
|
171
181
|
}
|
|
172
182
|
else {
|
|
173
|
-
qb = qb.orWhere(`${
|
|
183
|
+
qb = qb.orWhere(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
186
|
});
|
|
@@ -178,6 +188,37 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
178
188
|
}
|
|
179
189
|
});
|
|
180
190
|
}
|
|
191
|
+
if (relations && relations.length > 0) {
|
|
192
|
+
relations.forEach((relation) => {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
if (relation) {
|
|
195
|
+
query.innerJoin(`${modelName}.${relation.model}`, relation.model);
|
|
196
|
+
(_a = relation.searchs) === null || _a === void 0 ? void 0 : _a.forEach((valueSearch) => {
|
|
197
|
+
if (valueSearch) {
|
|
198
|
+
query = query.andWhere(`${relation.model}.${valueSearch.query}`, { [valueSearch.key]: valueSearch.value });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
(_b = relation.additionalSearchOr) === null || _b === void 0 ? void 0 : _b.forEach((group) => {
|
|
202
|
+
if (group) {
|
|
203
|
+
query.andWhere(new typeorm_1.Brackets((qb) => {
|
|
204
|
+
let index = 0;
|
|
205
|
+
group.forEach((value) => {
|
|
206
|
+
if (value) {
|
|
207
|
+
if (index === 0) {
|
|
208
|
+
qb = qb.where(`${relation.model}.${value.query}`, { [value.key]: value.value });
|
|
209
|
+
index++;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
qb = qb.orWhere(`${relation.model}.${value.query}`, { [value.key]: value.value });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
181
222
|
return query;
|
|
182
223
|
}
|
|
183
224
|
generateRawCount(query) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import IMultiJoin from "./multi.join.interface";
|
|
2
|
+
import ISearchQuery from "./search.query.interface";
|
|
3
|
+
export default interface IFindAllCount {
|
|
4
|
+
search: ISearchQuery[];
|
|
5
|
+
additionalSearchOr?: ISearchQuery[][];
|
|
6
|
+
sortBy?: string;
|
|
7
|
+
relations?: IMultiJoin[];
|
|
8
|
+
maxCount?: number;
|
|
9
|
+
offset?: number;
|
|
10
|
+
}
|