@provis/provis-common-be-module 2.6.55 → 2.6.57

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.
@@ -19,6 +19,7 @@ export declare class MainRepository<T> extends Repository<T> {
19
19
  summaryField({ fieldToSum, search, additionalSearchOr, relations, subqueryIns, }: ISearchSummary): Promise<any>;
20
20
  findAllAndCount({ search, additionalSearchOr, relations, subqueryIns, sortBy, offset, maxCount, }: IFindAllCount): Promise<[number, T[]]>;
21
21
  private applySearchConditions;
22
+ private subqueryInPredicate;
22
23
  private generateRawCount;
23
24
  private generateRawOrder;
24
25
  private convertRawFilter;
@@ -174,17 +174,28 @@ class MainRepository extends typeorm_1.Repository {
174
174
  if (additionalSearchOr && additionalSearchOr.length > 0) {
175
175
  additionalSearchOr.forEach((group) => {
176
176
  if (group) {
177
+ // grup bisa berupa ISearchQuery[] (lama) atau { searchs, subqueryIns } (baru)
178
+ const searchs = Array.isArray(group) ? group : (group.searchs || []);
179
+ const groupSubqueryIns = Array.isArray(group) ? [] : (group.subqueryIns || []);
177
180
  query.andWhere(new typeorm_1.Brackets((qb) => {
178
181
  let index = 0;
179
- group.forEach((value) => {
182
+ const orAdd = (where, parameters) => {
183
+ if (index === 0) {
184
+ qb.where(where, parameters);
185
+ index++;
186
+ }
187
+ else {
188
+ qb.orWhere(where, parameters);
189
+ }
190
+ };
191
+ searchs.forEach((value) => {
180
192
  if (value) {
181
- if (index === 0) {
182
- qb = qb.where(`${modelName}.${value.query}`, { [value.key]: value.value });
183
- index++;
184
- }
185
- else {
186
- qb = qb.orWhere(`${modelName}.${value.query}`, { [value.key]: value.value });
187
- }
193
+ orAdd(`${modelName}.${value.query}`, { [value.key]: value.value });
194
+ }
195
+ });
196
+ groupSubqueryIns.forEach((sub) => {
197
+ if (sub) {
198
+ orAdd(this.subqueryInPredicate(modelName, sub));
188
199
  }
189
200
  });
190
201
  }));
@@ -246,48 +257,53 @@ class MainRepository extends typeorm_1.Repository {
246
257
  }
247
258
  if (subqueryIns && subqueryIns.length > 0) {
248
259
  subqueryIns.forEach((sub) => {
249
- const alias = sub.subqueryAlias || sub.subqueryTable;
250
- query = query.andWhere((qb) => {
251
- var _a, _b;
252
- const subQuery = qb.subQuery()
253
- .select(`${alias}.${sub.subquerySelectColumn}`)
254
- .from(sub.subqueryTable, alias);
255
- let subIdx = 0;
256
- (_a = sub.searchs) === null || _a === void 0 ? void 0 : _a.forEach((s) => {
257
- if (s) {
258
- if (subIdx === 0) {
259
- subQuery.where(`${alias}.${s.query}`, { [s.key]: s.value });
260
- }
261
- else {
262
- subQuery.andWhere(`${alias}.${s.query}`, { [s.key]: s.value });
263
- }
264
- subIdx++;
265
- }
266
- });
267
- (_b = sub.additionalSearchOr) === null || _b === void 0 ? void 0 : _b.forEach((group) => {
268
- if (group) {
269
- subQuery.andWhere(new typeorm_1.Brackets((sqb) => {
270
- let orIdx = 0;
271
- group.forEach((s) => {
272
- if (s) {
273
- if (orIdx === 0) {
274
- sqb.where(`${alias}.${s.query}`, { [s.key]: s.value });
275
- }
276
- else {
277
- sqb.orWhere(`${alias}.${s.query}`, { [s.key]: s.value });
278
- }
279
- orIdx++;
280
- }
281
- });
282
- }));
283
- }
284
- });
285
- return `${modelName}.${sub.column} IN ${subQuery.getQuery()}`;
286
- });
260
+ query = query.andWhere(this.subqueryInPredicate(modelName, sub));
287
261
  });
288
262
  }
289
263
  return query;
290
264
  }
265
+ // membangun predicate `model.col IN (SELECT ... WHERE ...)` untuk satu subqueryIn.
266
+ // dipakai baik saat di-AND-kan langsung (subqueryIns) maupun saat di-OR-kan di dalam additionalSearchOr.
267
+ subqueryInPredicate(modelName, sub) {
268
+ const alias = sub.subqueryAlias || sub.subqueryTable;
269
+ return (qb) => {
270
+ var _a, _b;
271
+ const subQuery = qb.subQuery()
272
+ .select(`${alias}.${sub.subquerySelectColumn}`)
273
+ .from(sub.subqueryTable, alias);
274
+ let subIdx = 0;
275
+ (_a = sub.searchs) === null || _a === void 0 ? void 0 : _a.forEach((s) => {
276
+ if (s) {
277
+ if (subIdx === 0) {
278
+ subQuery.where(`${alias}.${s.query}`, { [s.key]: s.value });
279
+ }
280
+ else {
281
+ subQuery.andWhere(`${alias}.${s.query}`, { [s.key]: s.value });
282
+ }
283
+ subIdx++;
284
+ }
285
+ });
286
+ (_b = sub.additionalSearchOr) === null || _b === void 0 ? void 0 : _b.forEach((group) => {
287
+ if (group) {
288
+ subQuery.andWhere(new typeorm_1.Brackets((sqb) => {
289
+ let orIdx = 0;
290
+ group.forEach((s) => {
291
+ if (s) {
292
+ if (orIdx === 0) {
293
+ sqb.where(`${alias}.${s.query}`, { [s.key]: s.value });
294
+ }
295
+ else {
296
+ sqb.orWhere(`${alias}.${s.query}`, { [s.key]: s.value });
297
+ }
298
+ orIdx++;
299
+ }
300
+ });
301
+ }));
302
+ }
303
+ });
304
+ return `${modelName}.${sub.column} IN ${subQuery.getQuery()}`;
305
+ };
306
+ }
291
307
  generateRawCount(query) {
292
308
  return `SELECT COUNT(*) as total FROM (${query}) as subQry`;
293
309
  }
@@ -36,7 +36,7 @@ const additionalCoverage = [
36
36
  {
37
37
  code: 'FLEXAS',
38
38
  desc: {
39
- en: 'Fire, Lightning, Explosion, Aircraft Impact, and Smoke',
39
+ en: 'Fire, Lightning, Explosion, Impact of Aircraft and Smoke',
40
40
  id: 'Kebakaran, Petir, Ledakan, Kejatuhan Pesawat Terbang, dan Asap',
41
41
  },
42
42
  insuredPerils: {
@@ -61,8 +61,8 @@ const additionalCoverage = [
61
61
  {
62
62
  code: 'RSMDCC',
63
63
  desc: {
64
- en: 'Riots, Strikes Malicious Damage and Civil Commotions Endorsement (Endorsemen Huru-hara)',
65
- id: 'Endorsemen Kerusuhan, Pemogokan, Perbuatan Jahat, Perusakan, dan Keonaran Sipil',
64
+ en: 'Riot, Strike, Malicious Damage, and Civil Commotion & Others',
65
+ id: 'Kerusuhan, Pemogokan, Penghalangan Bekerja, Perbuatan Jahat, dan Huru-hara',
66
66
  },
67
67
  insuredPerils: {
68
68
  true: {
@@ -89,8 +89,8 @@ const additionalCoverage = [
89
89
  {
90
90
  code: 'TSFWD',
91
91
  desc: {
92
- en: 'Tsunami, Including Flood, Windstorm, Tempest and Water Damage',
93
- id: 'Tsunami, termasuk Banjir, Badai Angin, Angin Ribut, dan Kerusakan akibat Air',
92
+ en: 'Typhoon, Storm, Flood, Water Damage',
93
+ id: 'Topan, Badai, Banjir, dan Kerusakan Akibat Air',
94
94
  },
95
95
  insuredPerils: {
96
96
  true: {
@@ -117,8 +117,8 @@ const additionalCoverage = [
117
117
  {
118
118
  code: 'EQ',
119
119
  desc: {
120
- en: 'Earthquake, Volcanic Eruption, Tsunami',
121
- id: 'Gempa Bumi, Letusan Gunung Berapi, Tsunami',
120
+ en: 'Earthquake, Volcanic Eruption and Tsunami',
121
+ id: 'Gempa Bumi, Letusan Gunung Berapi, dan Tsunami',
122
122
  },
123
123
  insuredPerils: {
124
124
  true: {
@@ -1,9 +1,10 @@
1
1
  import IMultiJoin from "./multi.join.interface";
2
+ import ISearchOrGroup from "./search.or.group.interface";
2
3
  import ISearchQuery from "./search.query.interface";
3
4
  import ISubqueryIn from "./subquery.in.interface";
4
5
  export default interface IFindAllCount {
5
6
  search: ISearchQuery[];
6
- additionalSearchOr?: ISearchQuery[][];
7
+ additionalSearchOr?: (ISearchQuery[] | ISearchOrGroup)[];
7
8
  sortBy?: string;
8
9
  relations?: IMultiJoin[];
9
10
  subqueryIns?: ISubqueryIn[];
@@ -1,10 +1,11 @@
1
1
  import IMultiJoin from "./multi.join.interface";
2
+ import ISearchOrGroup from "./search.or.group.interface";
2
3
  import ISearchQuery from "./search.query.interface";
3
4
  import ISubqueryIn from "./subquery.in.interface";
4
5
  export default interface ISearchConditions {
5
6
  query: any;
6
7
  search?: ISearchQuery[];
7
- additionalSearchOr?: ISearchQuery[][];
8
+ additionalSearchOr?: (ISearchQuery[] | ISearchOrGroup)[];
8
9
  relations?: IMultiJoin[];
9
10
  subqueryIns?: ISubqueryIn[];
10
11
  }
@@ -0,0 +1,6 @@
1
+ import ISearchQuery from "./search.query.interface";
2
+ import ISubqueryIn from "./subquery.in.interface";
3
+ export default interface ISearchOrGroup {
4
+ searchs?: ISearchQuery[];
5
+ subqueryIns?: ISubqueryIn[];
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,12 @@
1
1
  import IMultiJoin from "./multi.join.interface";
2
+ import ISearchOrGroup from "./search.or.group.interface";
2
3
  import ISearchQuery from "./search.query.interface";
3
4
  import ISubqueryIn from "./subquery.in.interface";
4
5
  import ISummaryField from "./summary.field.interface";
5
6
  export default interface ISearchSummary {
6
7
  fieldToSum: ISummaryField[];
7
8
  search: ISearchQuery[];
8
- additionalSearchOr?: ISearchQuery[][];
9
+ additionalSearchOr?: (ISearchQuery[] | ISearchOrGroup)[];
9
10
  relations?: IMultiJoin[];
10
11
  subqueryIns?: ISubqueryIn[];
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provis/provis-common-be-module",
3
- "version": "2.6.55",
3
+ "version": "2.6.57",
4
4
  "description": "This common module for Provis internal backend use lib",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {