@provis/provis-common-be-module 1.7.28 → 2.0.1

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.
@@ -0,0 +1,19 @@
1
+ import { DeepPartial, FindConditions, Repository } from 'typeorm';
2
+ import ISearchQuery from '../interface/search.query.interface';
3
+ import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
4
+ export declare class MainRepository<T> extends Repository<T> {
5
+ saveRepo(data: DeepPartial<T>): Promise<T>;
6
+ updateRepo(obj: DeepPartial<T>, updated: QueryDeepPartialEntity<T>): Promise<T>;
7
+ updateByConditions(conditions: FindConditions<T>, updated: QueryDeepPartialEntity<T>): Promise<import("typeorm").UpdateResult>;
8
+ selectFieldOnFindAllAndCount(): string[];
9
+ modelName(): string;
10
+ orderBy(): string;
11
+ getOrderData(sortBy: string): {
12
+ orderBy: string;
13
+ orderDirection: 'ASC' | 'DESC';
14
+ };
15
+ searchBracket(searchOr: any[], searchValues: (value: any) => Promise<ISearchQuery[]>): Promise<ISearchQuery[][]>;
16
+ summaryField(search: ISearchQuery[], fieldToSum: string[], additionalSearchOr?: ISearchQuery[][]): Promise<any>;
17
+ findAllAndCount(search: ISearchQuery[], maxCount?: number, offset?: number, sortBy?: string, additionalSearchOr?: ISearchQuery[][]): Promise<[number, T[]]>;
18
+ private applySearchConditions;
19
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MainRepository = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const helpers_1 = require("../helpers");
15
+ class MainRepository extends typeorm_1.Repository {
16
+ saveRepo(data) {
17
+ const _super = Object.create(null, {
18
+ save: { get: () => super.save }
19
+ });
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return yield _super.save.call(this, Object.assign(Object.assign({}, data), { createdDate: (0, helpers_1.getCurrentDate)(), updatedDate: (0, helpers_1.getCurrentDate)() }));
22
+ });
23
+ }
24
+ updateRepo(obj, updated) {
25
+ const _super = Object.create(null, {
26
+ save: { get: () => super.save }
27
+ });
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return yield _super.save.call(this, Object.assign(Object.assign(Object.assign({}, obj), updated), { updatedDate: (0, helpers_1.getCurrentDate)() }));
30
+ });
31
+ }
32
+ updateByConditions(conditions, updated) {
33
+ const _super = Object.create(null, {
34
+ update: { get: () => super.update }
35
+ });
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return yield _super.update.call(this, conditions, Object.assign(Object.assign({}, updated), { updatedDate: (0, helpers_1.getCurrentDate)() }));
38
+ });
39
+ }
40
+ selectFieldOnFindAllAndCount() {
41
+ return [`"${this.modelName()}".*`];
42
+ }
43
+ modelName() {
44
+ throw new Error('Model name is not set yet');
45
+ }
46
+ orderBy() {
47
+ return 'createdDate';
48
+ }
49
+ getOrderData(sortBy) {
50
+ const [field, direction] = (sortBy || `${this.orderBy()}.desc`).split('.');
51
+ return {
52
+ orderBy: field || this.orderBy(),
53
+ orderDirection: (direction || 'desc').toUpperCase(),
54
+ };
55
+ }
56
+ /*
57
+ searchOr: [
58
+ {
59
+ portLoadingCodeIn: kalogOutlet.join(','),
60
+ portDestinationCodeIn: kalogOutlet.join(','),
61
+ source: dataSource,
62
+ },
63
+ {
64
+ policyNumberIn: kalog.POLICY_NO,
65
+ },
66
+ ],
67
+ */
68
+ // async implementation(searchOr: any[]) {
69
+ // await this.searchBracket(searchOr, this.searchValueDeclaration);
70
+ // }
71
+ // async searchValueDeclaration(search: any): Promise<ISearchQuery[]> {
72
+ // return [
73
+ // searchValue({ searchValue: search, searchKey: 'certificateNumber', operatorValue: operator.OPERATOR_LIKE, keyName: 'certificateNumber' }),
74
+ // searchValue({ searchValue: search, searchKey: 'interestInsured', operatorValue: operator.OPERATOR_LIKE, keyName: 'interestInsured' }),
75
+ // ];
76
+ // }
77
+ /*
78
+ result:
79
+ [
80
+ [
81
+ {
82
+ query: 'portLoadingCode',
83
+ key: 'IN',
84
+ value: 'KALOG001',
85
+ },
86
+ {
87
+ query: 'portDestinationCode',
88
+ key: 'IN',
89
+ value: 'KALOG001',
90
+ },
91
+ {
92
+ query: 'source',
93
+ key: '=',
94
+ value: 'KALOG',
95
+ },
96
+ ],
97
+ [
98
+ {
99
+ query: 'policyNumber',
100
+ key: 'ilike',
101
+ value: '123456890',
102
+ },
103
+ ],
104
+ ],
105
+ */
106
+ searchBracket(searchOr, searchValues) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const result = [];
109
+ for (const search of searchOr) {
110
+ result.push(yield searchValues(search));
111
+ }
112
+ return result;
113
+ });
114
+ }
115
+ summaryField(search, fieldToSum, additionalSearchOr) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ let query = this.createQueryBuilder()
118
+ .select([
119
+ 'COUNT(1) AS totalRows',
120
+ ...fieldToSum.map((field) => `SUM(${field}) AS "${field.split('.').pop()}"`),
121
+ ]);
122
+ query = this.applySearchConditions(query, search, additionalSearchOr);
123
+ return query.getRawOne();
124
+ });
125
+ }
126
+ findAllAndCount(search_1) {
127
+ return __awaiter(this, arguments, void 0, function* (search, maxCount = 50, offset = 1, sortBy, additionalSearchOr) {
128
+ const skipItems = ((offset < 1 ? 1 : offset) - 1) * maxCount;
129
+ let query = this.createQueryBuilder().select(this.selectFieldOnFindAllAndCount());
130
+ query = this.applySearchConditions(query, search, additionalSearchOr);
131
+ const { orderBy, orderDirection } = this.getOrderData(sortBy);
132
+ return [
133
+ yield query.getCount(),
134
+ yield query
135
+ .orderBy(`${this.modelName()}.${orderBy}`, orderDirection)
136
+ .offset(skipItems)
137
+ .limit(maxCount)
138
+ .getMany(),
139
+ ];
140
+ });
141
+ }
142
+ applySearchConditions(query, search, additionalSearchOr) {
143
+ if (search.length) {
144
+ search.forEach((value, index) => {
145
+ if (index === 0) {
146
+ query = query.where(`${this.modelName()}.${value.query}`, { [value.key]: value.value });
147
+ }
148
+ else {
149
+ query = query.andWhere(`${this.modelName()}.${value.query}`, { [value.key]: value.value });
150
+ }
151
+ });
152
+ }
153
+ if (additionalSearchOr) {
154
+ additionalSearchOr.forEach((group) => {
155
+ query.andWhere(new typeorm_1.Brackets((qb) => {
156
+ group.forEach((value, index) => {
157
+ if (index === 0) {
158
+ qb.where(`${this.modelName()}.${value.query} = :${value.key}`, { [value.key]: value.value });
159
+ }
160
+ else {
161
+ qb.orWhere(`${this.modelName()}.${value.query} = :${value.key}`, { [value.key]: value.value });
162
+ }
163
+ });
164
+ }));
165
+ });
166
+ }
167
+ return query;
168
+ }
169
+ }
170
+ exports.MainRepository = MainRepository;
@@ -4,7 +4,7 @@ const config_1 = require("../constants/config");
4
4
  const getCurrentDate_1 = require("./getCurrentDate");
5
5
  const monthIndo = [
6
6
  'Januari',
7
- 'Febuari',
7
+ 'Februari',
8
8
  'Maret',
9
9
  'April',
10
10
  'Mei',
@@ -18,7 +18,7 @@ const monthIndo = [
18
18
  ];
19
19
  const monthEng = [
20
20
  'January',
21
- 'Febuary',
21
+ 'February',
22
22
  'March',
23
23
  'April',
24
24
  'May',
@@ -1,7 +1,4 @@
1
- declare const _default: ({ searchValue, searchKey, operatorValue, keyName, }: {
2
- searchValue: any;
3
- searchKey: string;
4
- operatorValue: string;
5
- keyName?: string;
6
- }) => any;
1
+ import ISearchQuery from "../interface/search.query.interface";
2
+ import ISearchValue from "../interface/search.value.interface";
3
+ declare const _default: ({ searchValue, searchKey, operatorValue, keyName, }: ISearchValue) => ISearchQuery | undefined;
7
4
  export default _default;
@@ -0,0 +1,5 @@
1
+ export default interface ISearchQuery {
2
+ query: string;
3
+ key: string;
4
+ value: string;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,6 @@
1
+ export default interface ISearchValue {
2
+ searchValue: string;
3
+ searchKey: string;
4
+ operatorValue: string;
5
+ keyName?: string;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provis/provis-common-be-module",
3
- "version": "1.7.28",
3
+ "version": "2.0.1",
4
4
  "description": "This common module for Provis internal backend use lib",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
  "axios": "^0.21.1",
15
15
  "js-sha512": "^0.9.0",
16
16
  "lodash": "^4.17.21",
17
+ "typeorm": "^0.2.25",
17
18
  "uniqid": "^5.3.0",
18
19
  "xlsx": "^0.16.8"
19
20
  },