@uniorganization/uni-lib 4.0.36 → 4.0.37

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.
@@ -90,3 +90,4 @@ export * from './service-center-distance-cache.entity';
90
90
  export * from './service-center-geocode-cache.entity';
91
91
  export * from './kenko.entity';
92
92
  export * from './ticket-service-center-match-process.entity';
93
+ export * from './ticket-service-center-match-loa-pricing.entity';
@@ -106,3 +106,4 @@ __exportStar(require("./service-center-distance-cache.entity"), exports);
106
106
  __exportStar(require("./service-center-geocode-cache.entity"), exports);
107
107
  __exportStar(require("./kenko.entity"), exports);
108
108
  __exportStar(require("./ticket-service-center-match-process.entity"), exports);
109
+ __exportStar(require("./ticket-service-center-match-loa-pricing.entity"), exports);
@@ -0,0 +1,12 @@
1
+ import { Users } from './usr.entity';
2
+ export declare class TicketServiceCenterMatchLoaPricingEntity {
3
+ id: number;
4
+ model: string;
5
+ symptom: string | null;
6
+ price: number;
7
+ createdBy?: Users | null;
8
+ createdById: number | null;
9
+ createdDate: Date;
10
+ updatedDate: Date;
11
+ deletedDate: Date | null;
12
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TicketServiceCenterMatchLoaPricingEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const usr_entity_1 = require("./usr.entity");
15
+ let TicketServiceCenterMatchLoaPricingEntity = class TicketServiceCenterMatchLoaPricingEntity {
16
+ };
17
+ exports.TicketServiceCenterMatchLoaPricingEntity = TicketServiceCenterMatchLoaPricingEntity;
18
+ __decorate([
19
+ (0, typeorm_1.PrimaryGeneratedColumn)(),
20
+ __metadata("design:type", Number)
21
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "id", void 0);
22
+ __decorate([
23
+ (0, typeorm_1.Column)({ name: 'model', type: 'varchar', nullable: false }),
24
+ __metadata("design:type", String)
25
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "model", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ name: 'symptom', type: 'varchar', nullable: true }),
28
+ __metadata("design:type", String)
29
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "symptom", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ name: 'price', type: 'numeric', precision: 10, scale: 2, nullable: false }),
32
+ __metadata("design:type", Number)
33
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "price", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.ManyToOne)(() => usr_entity_1.Users),
36
+ (0, typeorm_1.JoinColumn)({ name: 'created_by_id' }),
37
+ __metadata("design:type", usr_entity_1.Users)
38
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "createdBy", void 0);
39
+ __decorate([
40
+ (0, typeorm_1.Column)({ name: 'created_by_id', type: 'integer', nullable: true }),
41
+ __metadata("design:type", Number)
42
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "createdById", void 0);
43
+ __decorate([
44
+ (0, typeorm_1.CreateDateColumn)({ name: 'created_date', type: 'timestamp' }),
45
+ __metadata("design:type", Date)
46
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "createdDate", void 0);
47
+ __decorate([
48
+ (0, typeorm_1.UpdateDateColumn)({ name: 'updated_date', type: 'timestamp' }),
49
+ __metadata("design:type", Date)
50
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "updatedDate", void 0);
51
+ __decorate([
52
+ (0, typeorm_1.DeleteDateColumn)({ name: 'deleted_date', type: 'timestamp' }),
53
+ __metadata("design:type", Date)
54
+ ], TicketServiceCenterMatchLoaPricingEntity.prototype, "deletedDate", void 0);
55
+ exports.TicketServiceCenterMatchLoaPricingEntity = TicketServiceCenterMatchLoaPricingEntity = __decorate([
56
+ (0, typeorm_1.Entity)('ticket_service_center_match_loa_pricing', { schema: 'enr' })
57
+ ], TicketServiceCenterMatchLoaPricingEntity);
@@ -1,8 +1,15 @@
1
- import { DistanceMatrixResponseData, GeocodeResponseData } from '@googlemaps/google-maps-services-js';
1
+ import { GeocodeResponseData } from '@googlemaps/google-maps-services-js';
2
+ import { NormalizedDistanceMatrixResponse } from './google-maps.types';
2
3
  export declare class GoogleMapsService {
3
4
  private client;
4
5
  private readonly logger;
5
6
  constructor();
6
7
  getGeocoding(address: string): Promise<GeocodeResponseData>;
7
- getDistanceMatrix(origin: string, destination: string): Promise<DistanceMatrixResponseData>;
8
+ getDistanceMatrix(origin: string, destination: string): Promise<NormalizedDistanceMatrixResponse>;
9
+ private normalizeRouteMatrixResponse;
10
+ private extractFirstRouteMatrixElement;
11
+ private extractDurationSeconds;
12
+ private parseDurationSeconds;
13
+ private extractRouteStatus;
14
+ private stringifyHttpError;
8
15
  }
@@ -21,6 +21,7 @@ var GoogleMapsService_1;
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.GoogleMapsService = void 0;
23
23
  const common_1 = require("@nestjs/common");
24
+ const axios_1 = require("axios");
24
25
  const google_maps_services_js_1 = require("@googlemaps/google-maps-services-js");
25
26
  let GoogleMapsService = GoogleMapsService_1 = class GoogleMapsService {
26
27
  constructor() {
@@ -61,18 +62,36 @@ let GoogleMapsService = GoogleMapsService_1 = class GoogleMapsService {
61
62
  throw new Error('Google Maps API configuration missing');
62
63
  }
63
64
  try {
64
- const response = yield this.client.distancematrix({
65
- params: {
66
- origins: [origin],
67
- destinations: [destination],
68
- key: apiKey,
69
- units: google_maps_services_js_1.UnitSystem.imperial,
65
+ const requestBody = {
66
+ origins: [
67
+ {
68
+ waypoint: {
69
+ address: origin,
70
+ },
71
+ },
72
+ ],
73
+ destinations: [
74
+ {
75
+ waypoint: {
76
+ address: destination,
77
+ },
78
+ },
79
+ ],
80
+ travelMode: 'DRIVE',
81
+ units: 'IMPERIAL',
82
+ };
83
+ const response = yield axios_1.default.post('https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix', requestBody, {
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ 'X-Goog-Api-Key': apiKey,
87
+ 'X-Goog-FieldMask': 'originIndex,destinationIndex,duration,distanceMeters,status,condition',
70
88
  },
89
+ validateStatus: () => true,
71
90
  });
72
- if (response.status !== 200) {
73
- throw new Error(`Google Maps API returned status ${response.status}: ${response.data.error_message || ''}`);
91
+ if (response.status < 200 || response.status >= 300) {
92
+ throw new Error(`Google Routes API returned status ${response.status}: ${this.stringifyHttpError(response.data)}`);
74
93
  }
75
- return response.data;
94
+ return this.normalizeRouteMatrixResponse(response.data, origin, destination);
76
95
  }
77
96
  catch (e) {
78
97
  this.logger.error(`Google Maps API Error: ${e.message}`, e.stack);
@@ -80,6 +99,93 @@ let GoogleMapsService = GoogleMapsService_1 = class GoogleMapsService {
80
99
  }
81
100
  });
82
101
  }
102
+ normalizeRouteMatrixResponse(data, origin, destination) {
103
+ var _a;
104
+ const element = this.extractFirstRouteMatrixElement(data);
105
+ if (!element) {
106
+ throw new Error('Google Routes API returned an empty route matrix response');
107
+ }
108
+ const distanceMeters = Number((_a = element.distanceMeters) !== null && _a !== void 0 ? _a : 0);
109
+ const durationSeconds = this.extractDurationSeconds(element.duration);
110
+ return {
111
+ origin_addresses: [origin],
112
+ destination_addresses: [destination],
113
+ rows: [
114
+ {
115
+ elements: [
116
+ {
117
+ status: this.extractRouteStatus(element),
118
+ distance: {
119
+ value: distanceMeters,
120
+ text: `${(distanceMeters / 1609.344).toFixed(1)} mi`,
121
+ },
122
+ duration: {
123
+ value: durationSeconds,
124
+ text: `${durationSeconds}s`,
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ ],
130
+ routeMatrix: [element],
131
+ };
132
+ }
133
+ extractFirstRouteMatrixElement(data) {
134
+ var _a, _b, _c, _d;
135
+ if (Array.isArray(data)) {
136
+ return (_a = data[0]) !== null && _a !== void 0 ? _a : null;
137
+ }
138
+ if (data && typeof data === 'object') {
139
+ const record = data;
140
+ if (Array.isArray(record.routeMatrix)) {
141
+ return (_b = record.routeMatrix[0]) !== null && _b !== void 0 ? _b : null;
142
+ }
143
+ if (Array.isArray(record.matrix)) {
144
+ return (_c = record.matrix[0]) !== null && _c !== void 0 ? _c : null;
145
+ }
146
+ if (Array.isArray(record.rows)) {
147
+ const firstRow = record.rows[0];
148
+ if (firstRow && Array.isArray(firstRow.elements)) {
149
+ return (_d = firstRow.elements[0]) !== null && _d !== void 0 ? _d : null;
150
+ }
151
+ }
152
+ }
153
+ return null;
154
+ }
155
+ extractDurationSeconds(duration) {
156
+ if (!duration) {
157
+ return 0;
158
+ }
159
+ return this.parseDurationSeconds(duration);
160
+ }
161
+ parseDurationSeconds(value) {
162
+ const match = value.match(/^(-?\d+(?:\.\d+)?)s$/);
163
+ if (!match) {
164
+ const fallback = Number(value);
165
+ return Number.isFinite(fallback) ? Math.max(0, Math.round(fallback)) : 0;
166
+ }
167
+ return Math.max(0, Math.round(Number(match[1])));
168
+ }
169
+ extractRouteStatus(element) {
170
+ if (element.status && typeof element.status === 'object') {
171
+ const status = element.status;
172
+ if (typeof status.message === 'string' && status.message.trim()) {
173
+ return status.message;
174
+ }
175
+ }
176
+ if (element.condition && element.condition.trim()) {
177
+ return element.condition;
178
+ }
179
+ return 'OK';
180
+ }
181
+ stringifyHttpError(data) {
182
+ var _a;
183
+ if (!data || typeof data !== 'object') {
184
+ return String(data);
185
+ }
186
+ const record = data;
187
+ return ((_a = record.error) === null || _a === void 0 ? void 0 : _a.message) || record.message || JSON.stringify(data);
188
+ }
83
189
  };
84
190
  exports.GoogleMapsService = GoogleMapsService;
85
191
  exports.GoogleMapsService = GoogleMapsService = GoogleMapsService_1 = __decorate([
@@ -0,0 +1,75 @@
1
+ export type RouteMatrixElementCondition = 'ROUTE_MATRIX_ELEMENT_CONDITION_UNSPECIFIED' | 'ROUTE_EXISTS' | 'ROUTE_NOT_FOUND';
2
+ export type RouteTravelMode = 'DRIVE' | 'BICYCLE' | 'WALK' | 'TWO_WHEELER' | 'TRANSIT';
3
+ export type RouteUnits = 'METRIC' | 'IMPERIAL';
4
+ export interface GoogleRpcStatus {
5
+ code: number;
6
+ message?: string;
7
+ details?: unknown[];
8
+ }
9
+ export interface ComputeRouteMatrixLatLng {
10
+ latitude: number;
11
+ longitude: number;
12
+ }
13
+ export interface ComputeRouteMatrixLocation {
14
+ latLng: ComputeRouteMatrixLatLng;
15
+ }
16
+ export interface ComputeRouteMatrixWaypoint {
17
+ address?: string;
18
+ placeId?: string;
19
+ location?: ComputeRouteMatrixLocation;
20
+ via?: boolean;
21
+ vehicleStopover?: boolean;
22
+ sideOfRoad?: boolean;
23
+ }
24
+ export interface ComputeRouteMatrixOrigin {
25
+ waypoint: ComputeRouteMatrixWaypoint;
26
+ routeModifiers?: Record<string, unknown>;
27
+ }
28
+ export interface ComputeRouteMatrixDestination {
29
+ waypoint: ComputeRouteMatrixWaypoint;
30
+ }
31
+ export interface ComputeRouteMatrixRequestBody {
32
+ origins: ComputeRouteMatrixOrigin[];
33
+ destinations: ComputeRouteMatrixDestination[];
34
+ travelMode: RouteTravelMode;
35
+ units?: RouteUnits;
36
+ routingPreference?: string;
37
+ departureTime?: string;
38
+ arrivalTime?: string;
39
+ languageCode?: string;
40
+ regionCode?: string;
41
+ extraComputations?: string[];
42
+ trafficModel?: string;
43
+ transitPreferences?: Record<string, unknown>;
44
+ }
45
+ export interface ComputeRouteMatrixElement {
46
+ originIndex?: number;
47
+ destinationIndex?: number;
48
+ status?: GoogleRpcStatus;
49
+ condition?: RouteMatrixElementCondition;
50
+ distanceMeters?: number;
51
+ duration?: string;
52
+ staticDuration?: string;
53
+ travelAdvisory?: Record<string, unknown>;
54
+ fallbackInfo?: Record<string, unknown>;
55
+ }
56
+ export type ComputeRouteMatrixResponse = ComputeRouteMatrixElement[];
57
+ export interface NormalizedDistanceMatrixElement {
58
+ status: string;
59
+ distance: {
60
+ value: number;
61
+ text: string;
62
+ };
63
+ duration: {
64
+ value: number;
65
+ text: string;
66
+ };
67
+ }
68
+ export interface NormalizedDistanceMatrixResponse {
69
+ origin_addresses: string[];
70
+ destination_addresses: string[];
71
+ rows: Array<{
72
+ elements: NormalizedDistanceMatrixElement[];
73
+ }>;
74
+ routeMatrix: ComputeRouteMatrixElement[];
75
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,4 +2,5 @@ export * from './common';
2
2
  export * from './encryption';
3
3
  export * from './google-maps/google-maps.module';
4
4
  export * from './google-maps/google-maps.service';
5
+ export * from './google-maps/google-maps.types';
5
6
  export * from './file-storage';
@@ -18,4 +18,5 @@ __exportStar(require("./common"), exports);
18
18
  __exportStar(require("./encryption"), exports);
19
19
  __exportStar(require("./google-maps/google-maps.module"), exports);
20
20
  __exportStar(require("./google-maps/google-maps.service"), exports);
21
+ __exportStar(require("./google-maps/google-maps.types"), exports);
21
22
  __exportStar(require("./file-storage"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniorganization/uni-lib",
3
- "version": "4.0.36",
3
+ "version": "4.0.37",
4
4
  "description": "UNI Library",
5
5
  "author": "Jhomiguel",
6
6
  "main": "dist/index.js",