@provis/provis-common-be-module 2.1.1 → 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 +52 -10
- 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;
|
|
@@ -108,9 +108,10 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
108
108
|
*/
|
|
109
109
|
searchBracket(searchOr, searchValues) {
|
|
110
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
// object searchOr -> searchOr[0]={"portLoadingCodeIn":"ZXY001,ZXY022","portDestinationCodeIn":"ZXY001,ZXY022","source":"KALOG"}&searchOr[1]={"policyNumberIn":"10103092500014,10103092400066"}
|
|
111
112
|
const result = [];
|
|
112
113
|
for (const search of searchOr) {
|
|
113
|
-
result.push(yield searchValues(search));
|
|
114
|
+
result.push(yield searchValues(JSON.parse(search)));
|
|
114
115
|
}
|
|
115
116
|
return result;
|
|
116
117
|
});
|
|
@@ -120,17 +121,26 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
120
121
|
let query = this.createQueryBuilder()
|
|
121
122
|
.select([
|
|
122
123
|
'COUNT(1) AS totalRows',
|
|
123
|
-
...fieldToSum.map((field) => `SUM(${field}) AS "${field.
|
|
124
|
+
...fieldToSum.map((field) => `SUM(${field.columnName}) AS "${field.aliasColumnName || field.columnName}"`),
|
|
124
125
|
]);
|
|
125
|
-
query = this.applySearchConditions(
|
|
126
|
+
query = this.applySearchConditions({
|
|
127
|
+
query,
|
|
128
|
+
search,
|
|
129
|
+
additionalSearchOr,
|
|
130
|
+
});
|
|
126
131
|
return query.getRawOne();
|
|
127
132
|
});
|
|
128
133
|
}
|
|
129
|
-
findAllAndCount(search,
|
|
134
|
+
findAllAndCount({ search, additionalSearchOr, relations, sortBy, offset = 1, maxCount = 50, }) {
|
|
130
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
136
|
const skipItems = ((offset < 1 ? 1 : offset) - 1) * maxCount;
|
|
132
137
|
let query = this.createQueryBuilder().select(this.selectFieldOnFindAllAndCount());
|
|
133
|
-
query = this.applySearchConditions(
|
|
138
|
+
query = this.applySearchConditions({
|
|
139
|
+
query,
|
|
140
|
+
search,
|
|
141
|
+
additionalSearchOr,
|
|
142
|
+
relations,
|
|
143
|
+
});
|
|
134
144
|
const { orderBy, orderDirection } = this.getOrderData(sortBy);
|
|
135
145
|
return [
|
|
136
146
|
yield query.getCount(),
|
|
@@ -142,17 +152,18 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
142
152
|
];
|
|
143
153
|
});
|
|
144
154
|
}
|
|
145
|
-
applySearchConditions(query, search, additionalSearchOr) {
|
|
155
|
+
applySearchConditions({ query, search, additionalSearchOr, relations, }) {
|
|
156
|
+
const modelName = this.modelName();
|
|
146
157
|
if (search && search.length > 0) {
|
|
147
158
|
let index = 0;
|
|
148
159
|
search.forEach((value) => {
|
|
149
160
|
if (value) {
|
|
150
161
|
if (index === 0) {
|
|
151
|
-
query = query.where(`${
|
|
162
|
+
query = query.where(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
152
163
|
index++;
|
|
153
164
|
}
|
|
154
165
|
else {
|
|
155
|
-
query = query.andWhere(`${
|
|
166
|
+
query = query.andWhere(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
156
167
|
}
|
|
157
168
|
}
|
|
158
169
|
});
|
|
@@ -165,11 +176,11 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
165
176
|
group.forEach((value) => {
|
|
166
177
|
if (value) {
|
|
167
178
|
if (index === 0) {
|
|
168
|
-
qb = qb.where(`${
|
|
179
|
+
qb = qb.where(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
169
180
|
index++;
|
|
170
181
|
}
|
|
171
182
|
else {
|
|
172
|
-
qb = qb.orWhere(`${
|
|
183
|
+
qb = qb.orWhere(`${modelName}.${value.query}`, { [value.key]: value.value });
|
|
173
184
|
}
|
|
174
185
|
}
|
|
175
186
|
});
|
|
@@ -177,6 +188,37 @@ class MainRepository extends typeorm_1.Repository {
|
|
|
177
188
|
}
|
|
178
189
|
});
|
|
179
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
|
+
}
|
|
180
222
|
return query;
|
|
181
223
|
}
|
|
182
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
|
+
}
|