@provis/provis-common-be-module 2.6.54 → 2.6.56

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.
Files changed (38) hide show
  1. package/dist/class/main.repository.d.ts +1 -0
  2. package/dist/class/main.repository.js +66 -50
  3. package/dist/constants/claim/general.js +1 -1
  4. package/dist/constants/claim/kalog.js +1 -1
  5. package/dist/constants/claim/loket.js +40 -40
  6. package/dist/constants/claim/motorVehicle.js +1 -1
  7. package/dist/constants/claim/travel.js +1 -1
  8. package/dist/constants/config.js +2 -2
  9. package/dist/constants/invoice/status.d.ts +11 -0
  10. package/dist/constants/invoice/status.js +21 -0
  11. package/dist/constants/product.js +12 -12
  12. package/dist/constants/source.js +1 -1
  13. package/dist/helpers/alphaNumericCleansing.js +1 -1
  14. package/dist/helpers/amountDescription.js +1 -1
  15. package/dist/helpers/axiosGet.js +1 -1
  16. package/dist/helpers/axiosPost.js +1 -1
  17. package/dist/helpers/axiosPut.js +1 -1
  18. package/dist/helpers/calculateByType.js +1 -1
  19. package/dist/helpers/calculateForNullable.js +6 -6
  20. package/dist/helpers/getHeaderUser.js +4 -4
  21. package/dist/helpers/loop.js +2 -2
  22. package/dist/helpers/loopBackward.js +2 -2
  23. package/dist/helpers/readExcel.d.ts +0 -2
  24. package/dist/interface/find.all.count.interface.d.ts +2 -1
  25. package/dist/interface/search.conditions.interface.d.ts +2 -1
  26. package/dist/interface/search.or.group.interface.d.ts +6 -0
  27. package/dist/interface/search.or.group.interface.js +2 -0
  28. package/dist/interface/search.summary.interface.d.ts +2 -1
  29. package/docs/search-conditions.md +218 -0
  30. package/package.json +1 -1
  31. package/dist/constants/bankAccount.d.ts +0 -8
  32. package/dist/constants/bankAccount.js +0 -54
  33. package/dist/constants/product/coretax.d.ts +0 -12
  34. package/dist/constants/product/coretax.js +0 -14
  35. package/dist/constants/product/mv.d.ts +0 -30
  36. package/dist/constants/product/mv.js +0 -158
  37. package/dist/constants/product/property/occupation.d.ts +0 -5
  38. package/dist/constants/product/property/occupation.js +0 -1725
@@ -0,0 +1,218 @@
1
+ # Search Conditions — `findAllAndCount` / `summaryField`
2
+
3
+ Panduan memakai filter pada `MainRepository` (`src/class/main.repository.ts`).
4
+
5
+ Semua method query (`findAllAndCount`, `summaryField`) menerima opsi berikut:
6
+
7
+ | Field | Tipe | Penggabungan |
8
+ | ------------------- | ----------------------------------------- | ------------------------------------- |
9
+ | `search` | `ISearchQuery[]` | semua di-**AND** (filter wajib) |
10
+ | `additionalSearchOr`| `(ISearchQuery[] \| ISearchOrGroup)[]` | antar-grup **AND**, isi grup **OR** |
11
+ | `relations` | `IMultiJoin[]` | join + kondisi |
12
+ | `subqueryIns` | `ISubqueryIn[]` | masing-masing di-**AND** ke query |
13
+
14
+ Bentuk `ISearchQuery`:
15
+
16
+ ```ts
17
+ interface ISearchQuery {
18
+ query: string; // fragmen SQL, mis. 'status = :status' atau 'status IN (:...statuses)'
19
+ key: string; // nama parameter
20
+ value: string | number | boolean | Date;
21
+ }
22
+ ```
23
+
24
+ ---
25
+
26
+ ## 1. `search` — filter wajib (AND)
27
+
28
+ ```ts
29
+ search: [
30
+ { query: 'companyId = :companyId', key: 'companyId', value: 10 },
31
+ { query: 'isDeleted = :isDeleted', key: 'isDeleted', value: false },
32
+ ]
33
+ ```
34
+
35
+ ```sql
36
+ WHERE model.companyId = :companyId AND model.isDeleted = :isDeleted
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 2. `additionalSearchOr` — grup OR
42
+
43
+ Tiap **grup** di-AND-kan satu sama lain; **anggota dalam satu grup** di-OR-kan. Berguna untuk pencarian kata kunci di beberapa kolom.
44
+
45
+ ```ts
46
+ additionalSearchOr: [
47
+ [
48
+ { query: 'policyNumber ILIKE :kw', key: 'kw', value: '%123%' },
49
+ { query: 'certificateNumber ILIKE :kw2', key: 'kw2', value: '%123%' },
50
+ ],
51
+ ]
52
+ ```
53
+
54
+ ```sql
55
+ AND (model.policyNumber ILIKE :kw OR model.certificateNumber ILIKE :kw2)
56
+ ```
57
+
58
+ > Catatan: pakai key parameter yang **unik** per kondisi agar tidak saling menimpa.
59
+
60
+ ---
61
+
62
+ ## 3. `subqueryIns` — `column IN (subquery)`
63
+
64
+ Mencocokkan kolom table utama terhadap hasil sebuah subquery. Tiap entri di-**AND**-kan ke query utama.
65
+
66
+ Bentuk `ISubqueryIn`:
67
+
68
+ ```ts
69
+ interface ISubqueryIn {
70
+ column: string; // kolom pada table utama (sisi kiri IN)
71
+ subqueryTable: string; // table sumber subquery
72
+ subqueryAlias?: string; // alias table subquery
73
+ subquerySelectColumn: string; // kolom yang di-SELECT subquery (sisi kanan IN)
74
+ searchs?: ISearchQuery[]; // kondisi di dalam subquery, di-AND
75
+ additionalSearchOr?: ISearchQuery[][]; // kondisi OR di dalam subquery
76
+ }
77
+ ```
78
+
79
+ ### Contoh — kondisi AND di dalam subquery
80
+
81
+ ```ts
82
+ subqueryIns: [{
83
+ column: 'id',
84
+ subqueryTable: 'declarationAttachment',
85
+ subqueryAlias: 'da',
86
+ subquerySelectColumn: 'declarationId',
87
+ searchs: [
88
+ { query: 'containerNo = :cn', key: 'cn', value: 'ABC123' },
89
+ { query: 'isActive = :ia', key: 'ia', value: true },
90
+ ],
91
+ }]
92
+ ```
93
+
94
+ ```sql
95
+ AND model.id IN (
96
+ SELECT da.declarationId FROM declarationAttachment da
97
+ WHERE da.containerNo = :cn AND da.isActive = :ia
98
+ )
99
+ ```
100
+
101
+ ### Contoh — kondisi OR di dalam subquery
102
+
103
+ Pakai `additionalSearchOr` (satu grup → anggotanya OR):
104
+
105
+ ```ts
106
+ subqueryIns: [{
107
+ column: 'id',
108
+ subqueryTable: 'declarationAttachment',
109
+ subqueryAlias: 'da',
110
+ subquerySelectColumn: 'declarationId',
111
+ additionalSearchOr: [[
112
+ { query: 'containerNo LIKE :cn', key: 'cn', value: '%X%' },
113
+ { query: 'sealNo LIKE :sn', key: 'sn', value: '%X%' },
114
+ ]],
115
+ }]
116
+ ```
117
+
118
+ ```sql
119
+ AND model.id IN (
120
+ SELECT da.declarationId FROM declarationAttachment da
121
+ WHERE (da.containerNo LIKE :cn OR da.sealNo LIKE :sn)
122
+ )
123
+ ```
124
+
125
+ ---
126
+
127
+ ## 4. Subquery sebagai bagian dari grup OR (`ISearchOrGroup`)
128
+
129
+ Kalau pencarian `IN (subquery)` harus di-**OR**-kan bersama field text search (mis. "cocok kalau field declaration cocok **ATAU** attachment-nya cocok"), masukkan subquery ke dalam grup `additionalSearchOr` berbentuk objek:
130
+
131
+ ```ts
132
+ interface ISearchOrGroup {
133
+ searchs?: ISearchQuery[]; // kondisi field di table utama
134
+ subqueryIns?: ISubqueryIn[]; // subquery IN, di-OR-kan dengan searchs
135
+ }
136
+ ```
137
+
138
+ Semua anggota grup (`searchs` + `subqueryIns`) digabung **OR** di dalam satu bracket, lalu bracket itu di-**AND**-kan ke query (jadi filter wajib tetap berlaku).
139
+
140
+ ### Contoh lengkap
141
+
142
+ ```ts
143
+ const attachmentSearchs = [
144
+ { query: 'containerNo LIKE :cn', key: 'cn', value: '%X%' },
145
+ { query: 'sealNo LIKE :sn', key: 'sn', value: '%X%' },
146
+ ];
147
+
148
+ const attachmentSubquery = {
149
+ column: 'id',
150
+ subqueryTable: 'declarationAttachment',
151
+ subqueryAlias: 'da',
152
+ subquerySelectColumn: 'declarationId',
153
+ additionalSearchOr: [attachmentSearchs], // (da.containerNo LIKE :cn OR da.sealNo LIKE :sn)
154
+ };
155
+
156
+ const [total, data] = await repo.findAllAndCount({
157
+ search: [
158
+ { query: 'companyId = :companyId', key: 'companyId', value: 10 }, // filter wajib (AND)
159
+ ],
160
+ additionalSearchOr: [
161
+ {
162
+ searchs: [
163
+ { query: 'policyNumber ILIKE :kw', key: 'kw', value: '%X%' },
164
+ { query: 'certificateNumber ILIKE :kw2', key: 'kw2', value: '%X%' },
165
+ ],
166
+ subqueryIns: [attachmentSubquery],
167
+ },
168
+ ],
169
+ });
170
+ ```
171
+
172
+ ```sql
173
+ WHERE model.companyId = :companyId -- filter wajib, AND
174
+ AND (
175
+ model.policyNumber ILIKE :kw
176
+ OR model.certificateNumber ILIKE :kw2
177
+ OR model.id IN (
178
+ SELECT da.declarationId FROM declarationAttachment da
179
+ WHERE (da.containerNo LIKE :cn OR da.sealNo LIKE :sn)
180
+ )
181
+ )
182
+ ```
183
+
184
+ ### Menyisipkan subquery ke grup `searchOr` yang sudah ada
185
+
186
+ Kalau grup OR dibangun dari `searchBracket(search.searchOr, ...)`, sisipkan subquery ke grup pertama:
187
+
188
+ ```ts
189
+ const searchOrGroups = search.searchOr
190
+ ? await repo.searchBracket(search.searchOr, this.searchValueDeclaration)
191
+ : [];
192
+
193
+ const additionalSearchOr = (() => {
194
+ if (attachmentSearchs.length === 0) return searchOrGroups;
195
+ if (searchOrGroups.length === 0) return [{ subqueryIns: [attachmentSubquery] }];
196
+ return searchOrGroups.map((g, i) =>
197
+ i === 0 ? { searchs: g, subqueryIns: [attachmentSubquery] } : g
198
+ );
199
+ })();
200
+
201
+ const [total, data] = await repo.findAllAndCount({
202
+ search: this.searchValueDeclaration(search, user),
203
+ additionalSearchOr,
204
+ maxCount, offset, sortBy: search.sortBy,
205
+ });
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Ringkasan AND vs OR
211
+
212
+ | Mau... | Pakai |
213
+ | --------------------------------------------------- | ----------------------------------------------------------- |
214
+ | Filter wajib (selalu berlaku) | `search` |
215
+ | OR antar beberapa kolom (search box) | `additionalSearchOr: [[ ... ]]` |
216
+ | `col IN (subquery)`, di-AND ke query | `subqueryIns: [ ... ]` |
217
+ | OR **di dalam** subquery | `subqueryIns[].additionalSearchOr` |
218
+ | `col IN (subquery)` di-**OR** dengan field lain | grup objek `{ searchs, subqueryIns }` di `additionalSearchOr` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provis/provis-common-be-module",
3
- "version": "2.6.54",
3
+ "version": "2.6.56",
4
4
  "description": "This common module for Provis internal backend use lib",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,8 +0,0 @@
1
- declare const bankAccount: {
2
- code: string;
3
- desc: {
4
- id: string;
5
- en: string;
6
- };
7
- }[];
8
- export default bankAccount;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bankAccount = [
4
- {
5
- code: 'BCA2000',
6
- desc: {
7
- id: 'BCA 5455682000',
8
- en: 'BCA 5455682000',
9
- }
10
- },
11
- {
12
- code: 'BCA2999',
13
- desc: {
14
- id: 'BCA 5455682999',
15
- en: 'BCA 5455682999',
16
- }
17
- },
18
- {
19
- code: 'OCBC371-IDR',
20
- desc: {
21
- id: 'OCBC IDR 111800004371',
22
- en: 'OCBC IDR 111800004371',
23
- }
24
- },
25
- {
26
- code: 'OCBC371-USD',
27
- desc: {
28
- id: 'OCBC USD 111800004371',
29
- en: 'OCBC USD 111800004371',
30
- }
31
- },
32
- {
33
- code: 'PERMATA4371',
34
- desc: {
35
- id: 'Permata 0980-9340-683',
36
- en: 'Permata 0980-9340-683',
37
- }
38
- },
39
- {
40
- code: 'PERMATA4371',
41
- desc: {
42
- id: 'QNB 1220-004544-001',
43
- en: 'QNB 1220-004544-001',
44
- }
45
- },
46
- {
47
- code: 'BTPN3068',
48
- desc: {
49
- id: 'BTPN Syariah 1035883068',
50
- en: 'BTPN Syariah 1035883068',
51
- }
52
- },
53
- ];
54
- exports.default = bankAccount;
@@ -1,12 +0,0 @@
1
- declare const coretax: {
2
- STATUS: {
3
- DRAFT: string;
4
- SUBMIT: string;
5
- CANCEL: string;
6
- };
7
- TYPE_CORETAX: {
8
- CREATE: string;
9
- UPDATE: string;
10
- };
11
- };
12
- export default coretax;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const coretax = {
4
- STATUS: {
5
- DRAFT: "0",
6
- SUBMIT: "100",
7
- CANCEL: "300",
8
- },
9
- TYPE_CORETAX: {
10
- CREATE: "CREATE",
11
- UPDATE: "UPDATE"
12
- },
13
- };
14
- exports.default = coretax;
@@ -1,30 +0,0 @@
1
- declare const insuranceType: {
2
- code: string;
3
- desc: {
4
- id: string;
5
- en: string;
6
- };
7
- }[];
8
- declare const regionCode: {
9
- code: string;
10
- desc: {
11
- id: string;
12
- en: string;
13
- };
14
- }[];
15
- declare const vehicleTypeCode: {
16
- code: string;
17
- desc: {
18
- id: string;
19
- en: string;
20
- };
21
- }[];
22
- declare const additionalCoverage: {
23
- code: string;
24
- desc: {
25
- id: string;
26
- en: string;
27
- };
28
- isVisible: boolean;
29
- }[];
30
- export { insuranceType, regionCode, vehicleTypeCode, additionalCoverage, };
@@ -1,158 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.additionalCoverage = exports.vehicleTypeCode = exports.regionCode = exports.insuranceType = void 0;
4
- const insuranceType = [
5
- {
6
- code: "all-risk",
7
- desc: {
8
- id: "Komprehensif",
9
- en: "Comprehensive",
10
- },
11
- },
12
- {
13
- code: "total-loss",
14
- desc: {
15
- id: "Kerugian Total",
16
- en: "Total Loss",
17
- },
18
- },
19
- ];
20
- exports.insuranceType = insuranceType;
21
- const regionCode = [
22
- {
23
- code: "RC001",
24
- desc: {
25
- id: "Wilayah 1",
26
- en: "Region 1",
27
- },
28
- },
29
- {
30
- code: "RC002",
31
- desc: {
32
- id: "Wilayah 2",
33
- en: "Region 2",
34
- },
35
- },
36
- {
37
- code: "RC003",
38
- desc: {
39
- id: "Wilayah 3",
40
- en: "Region 3",
41
- },
42
- },
43
- ];
44
- exports.regionCode = regionCode;
45
- const vehicleTypeCode = [
46
- {
47
- code: "VT001",
48
- desc: {
49
- id: "Jenis Kendaraan Non Bus dan Non Truk",
50
- en: "Types of Non-Bus and Non-Truck Vehicles",
51
- },
52
- },
53
- {
54
- code: "VT002",
55
- desc: {
56
- id: "Jenis Kendaraan Truk dan Pickup",
57
- en: "Vehicle Types Truck and Pickup",
58
- },
59
- },
60
- {
61
- code: "VT003",
62
- desc: {
63
- id: "Jenis Kendaraan Bus",
64
- en: "Vehicle Types Bus",
65
- },
66
- },
67
- {
68
- code: "VT004",
69
- desc: {
70
- id: "Jenis Kendaraan Roda 2 (dua)",
71
- en: "Type of 2 (two) Wheeled Vehicle",
72
- },
73
- },
74
- ];
75
- exports.vehicleTypeCode = vehicleTypeCode;
76
- const additionalCoverage = [
77
- {
78
- code: "TSFWD",
79
- desc: {
80
- id: "Topan, Badai, Banjir, Kerusakan Akibat Air",
81
- en: "Typhoon, Storm, Flood, Water Damage",
82
- },
83
- isVisible: true,
84
- },
85
- {
86
- code: "EQVET",
87
- desc: {
88
- id: "Gempa Bumi, Letusan Gunung Berapi dan Tsunami",
89
- en: "Earthquake, Volcanic Eruption and Tsunami",
90
- },
91
- isVisible: true,
92
- },
93
- {
94
- code: "SRCC",
95
- desc: {
96
- id: "Mogok Kerja, Kerusuhan dan Kerusuhan Sipil",
97
- en: "Strike, Riot & Civil Commotion",
98
- },
99
- isVisible: true,
100
- },
101
- {
102
- code: "PSATSI",
103
- desc: {
104
- id: "Terorisme dan Sabotase",
105
- en: "Terrorism and Sabotage",
106
- },
107
- isVisible: true,
108
- },
109
- {
110
- code: "TPL",
111
- desc: {
112
- id: "Tanggung Jawab Hukum Pihak Ketiga",
113
- en: "Third Party Liability",
114
- },
115
- isVisible: true,
116
- },
117
- {
118
- code: "PAD",
119
- desc: {
120
- id: "Kecelakaan Pengemudi",
121
- en: "Personal Accident Driver",
122
- },
123
- isVisible: true,
124
- },
125
- {
126
- code: "PAP",
127
- desc: {
128
- id: " Kcelakaan Penumpang",
129
- en: "Personal Accident Passenger",
130
- },
131
- isVisible: true,
132
- },
133
- {
134
- code: "TBOD",
135
- desc: {
136
- id: "Biaya Medis, Izin Bengkel, Tunjangan Ambulans, Ban dan Velg",
137
- en: "TBOD, Authorize Workshop, Ambulance Allowance, Tire and Wheel",
138
- },
139
- isVisible: true,
140
- },
141
- {
142
- code: "CASCO",
143
- desc: {
144
- id: "",
145
- en: "",
146
- },
147
- isVisible: false,
148
- },
149
- {
150
- code: "TLO",
151
- desc: {
152
- id: "",
153
- en: "",
154
- },
155
- isVisible: false,
156
- },
157
- ];
158
- exports.additionalCoverage = additionalCoverage;
@@ -1,5 +0,0 @@
1
- declare const ocupation: {
2
- id: number;
3
- name: string;
4
- }[];
5
- export default ocupation;