@vendit-dev/thirdparty-adapters 0.7.4 → 0.7.6-beta.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.
@@ -1,11 +1,14 @@
1
1
  import { DeregisterParkingDiscountCommand, DeregisterParkingPassCommand, ParkingThirdParty, RegisterParkingDiscountCommand, RegisterParkingPassCommand, SearchVehiclesByNumberCriteria, SearchVehiclesByNumberResult } from './parkingThirdParty.type';
2
- interface NiceParkingConfig {
2
+ export interface NiceParkingConfig {
3
3
  dbHost: string;
4
4
  dbPort: string;
5
5
  dbUserName: string;
6
6
  dbPassword: string;
7
7
  groupCode: string;
8
8
  placeCode: string;
9
+ maxParkingHoursPerMonth?: number;
10
+ parkingHoursToAlert?: number;
11
+ counponTypesInUse?: number[];
9
12
  }
10
13
  export declare class NiceParkThirdParty implements ParkingThirdParty {
11
14
  private configuration;
@@ -17,4 +20,3 @@ export declare class NiceParkThirdParty implements ParkingThirdParty {
17
20
  registerParkingPass(command: RegisterParkingPassCommand): Promise<boolean>;
18
21
  deregisterParkingPass(command: DeregisterParkingPassCommand): Promise<boolean>;
19
22
  }
20
- export {};
@@ -47,7 +47,10 @@ var NiceParkDbName = 'NPMU';
47
47
  var NiceParkThirdParty = /** @class */ (function () {
48
48
  function NiceParkThirdParty(configuration) {
49
49
  this.configuration = configuration;
50
- this.configuration.dbPort = '46000';
50
+ this.configuration.dbPort = configuration.dbPort || '46000';
51
+ this.configuration.counponTypesInUse = configuration.counponTypesInUse || [];
52
+ this.configuration.maxParkingHoursPerMonth = configuration.maxParkingHoursPerMonth;
53
+ this.configuration.parkingHoursToAlert = configuration.parkingHoursToAlert;
51
54
  this.sequelize = new sequelize_1.Sequelize(NiceParkDbName, configuration.dbUserName, configuration.dbPassword, {
52
55
  dialect: 'mssql',
53
56
  host: configuration.dbHost,
@@ -84,6 +87,7 @@ var NiceParkThirdParty = /** @class */ (function () {
84
87
  return [2 /*return*/, refinedResult];
85
88
  case 3:
86
89
  err_1 = _a.sent();
90
+ console.error('NiceParkThirdParty#searchVehiclesByNumber failed error: ', err_1);
87
91
  return [2 /*return*/, []];
88
92
  case 4: return [2 /*return*/];
89
93
  }
@@ -91,57 +95,73 @@ var NiceParkThirdParty = /** @class */ (function () {
91
95
  });
92
96
  };
93
97
  NiceParkThirdParty.prototype.registerParkingDiscount = function (command) {
98
+ var _a, _b, _c;
94
99
  return __awaiter(this, void 0, void 0, function () {
95
- var vehicleNumber, from, minutes, result, err_2;
96
- return __generator(this, function (_a) {
97
- switch (_a.label) {
100
+ var vehicleNumber, minutes, result, err_2;
101
+ return __generator(this, function (_d) {
102
+ switch (_d.label) {
98
103
  case 0:
99
- vehicleNumber = command.vehicleNumber, from = command.from, minutes = command.minutes;
100
- _a.label = 1;
104
+ vehicleNumber = command.vehicleNumber, minutes = command.minutes;
105
+ _d.label = 1;
101
106
  case 1:
102
- _a.trys.push([1, 3, , 4]);
103
- return [4 /*yield*/, this.sequelize.query("exec sp_External_Link_Discount '".concat(vehicleNumber, "', '1', '").concat(minutes, "', '").concat(this.configuration.placeCode || '000001', ";"))];
107
+ _d.trys.push([1, 3, , 4]);
108
+ if (!((_a = this.configuration.counponTypesInUse) === null || _a === void 0 ? void 0 : _a.includes(minutes))) {
109
+ console.error("this accommodation does not provide a coupon type ".concat(minutes, " for given minutes"));
110
+ return [2 /*return*/, false];
111
+ }
112
+ return [4 /*yield*/, this.sequelize.query("exec sp_External_Link_Discount '".concat(vehicleNumber, "', '1', '").concat(minutes, "', '").concat(this.configuration.placeCode || '000001', "';"))];
104
113
  case 2:
105
- result = _a.sent();
114
+ result = _d.sent();
106
115
  console.log('NiceParkThirdParty#registerParkingDiscount result: ', result);
107
- return [2 /*return*/, result[0].result === '1'];
116
+ // result is count of coupon issued
117
+ if (Number(((_b = result[0][0]) === null || _b === void 0 ? void 0 : _b.result) || 0) >= 1) {
118
+ console.log("".concat(minutes, " minutes coupon issued to Car ").concat(vehicleNumber, " with place code ").concat(this.configuration.placeCode));
119
+ }
120
+ return [2 /*return*/, Number(((_c = result[0][0]) === null || _c === void 0 ? void 0 : _c.result) || 0) >= 1];
108
121
  case 3:
109
- err_2 = _a.sent();
122
+ err_2 = _d.sent();
123
+ console.error('NiceParkThirdParty#registerParkingDiscount failed error: ', err_2);
110
124
  return [2 /*return*/, false];
111
125
  case 4: return [2 /*return*/];
112
126
  }
113
127
  });
114
128
  });
115
129
  };
130
+ // not provided by nice park
116
131
  NiceParkThirdParty.prototype.deregisterParkingDiscount = function (command) {
117
132
  throw new Error('Method not implemented in NicePark yet.');
118
133
  };
119
134
  NiceParkThirdParty.prototype.registerParkingPass = function (command) {
135
+ var _a, _b;
120
136
  return __awaiter(this, void 0, void 0, function () {
121
- var from, to, vehicleNumber, fromDateString, toDateString, result, err_3;
122
- return __generator(this, function (_a) {
123
- switch (_a.label) {
137
+ var from, to, vehicleNumber, fromDateString, toDateString, result, registered, err_3;
138
+ return __generator(this, function (_c) {
139
+ switch (_c.label) {
124
140
  case 0:
125
141
  from = command.from, to = command.to, vehicleNumber = command.vehicleNumber;
126
142
  fromDateString = (0, moment_1.default)(from).format('YYYYMMDD');
127
143
  toDateString = (0, moment_1.default)(to).format('YYYYMMDD');
128
- _a.label = 1;
144
+ _c.label = 1;
129
145
  case 1:
130
- _a.trys.push([1, 3, , 4]);
146
+ _c.trys.push([1, 3, , 4]);
131
147
  return [4 /*yield*/, this.sequelize.query("exec sp_External_Link_RegRegular_CODEIN '".concat(vehicleNumber, "', '").concat(fromDateString, "', '").concat(toDateString, "', '', '', '', '', '', '0', '").concat(this.configuration.groupCode, "';"))];
132
148
  case 2:
133
- result = _a.sent();
149
+ result = _c.sent();
134
150
  console.log('NiceParkThirdParty#registerParkingDiscount result: ', result);
135
- console.log("Car#".concat(vehicleNumber, " has been registered from ").concat(fromDateString, ", to ").concat(toDateString, " with group code ").concat(this.configuration.groupCode));
136
- return [2 /*return*/, result[0].result === '1'];
151
+ if (((_a = result[0]) === null || _a === void 0 ? void 0 : _a.result) === '1') {
152
+ console.log("Car ".concat(vehicleNumber, " has been registered from ").concat(fromDateString, ", to ").concat(toDateString, " with place code ").concat(this.configuration.placeCode));
153
+ }
154
+ registered = ((_b = result[0]) === null || _b === void 0 ? void 0 : _b.result) === '1';
155
+ return [2 /*return*/, registered];
137
156
  case 3:
138
- err_3 = _a.sent();
157
+ err_3 = _c.sent();
139
158
  return [2 /*return*/, false];
140
159
  case 4: return [2 /*return*/];
141
160
  }
142
161
  });
143
162
  });
144
163
  };
164
+ // not provided by nice park
145
165
  NiceParkThirdParty.prototype.deregisterParkingPass = function (command) {
146
166
  throw new Error('Method not implemented in NicePark yet.');
147
167
  };
@@ -73,21 +73,26 @@ export default class SmartAccessAdapter {
73
73
  lockList: SmartAccessRoomKey[];
74
74
  }>;
75
75
  getRoomsWithDevices: (accommodationId: string) => Promise<SmartAccessRoom[]>;
76
- createPinCodeForRoom: ({ roomId, accommodationId, userType, keyType, startDate, endDate, }: {
76
+ createPinCodeForRoom: ({ roomId, accommodationId, userType, keyType, startDate, endDate, pinCode, }: {
77
77
  roomId: string;
78
78
  accommodationId: string;
79
79
  userType: 'GUEST' | 'EMPLOYEE';
80
80
  keyType: 'SCHEDULE' | 'ONETIME';
81
81
  startDate: Date;
82
82
  endDate: Date;
83
+ /**
84
+ * @description 4~12자리 출입 비밀번호, 미입력 시 시스템에서 6자리 랜덤 키 발급(권장)
85
+ */
86
+ pinCode?: string | null | undefined;
83
87
  }) => Promise<any>;
84
- modifyPinCodeByKeyId: ({ keyId, accommodationId, userType, keyType, startDate, endDate, }: {
88
+ modifyPinCodeByKeyId: ({ keyId, accommodationId, userType, keyType, startDate, endDate, pinCode, }: {
85
89
  keyId: string;
86
90
  accommodationId: string;
87
91
  userType: 'GUEST' | 'EMPLOYEE';
88
92
  keyType: 'SCHEDULE' | 'ONETIME';
89
93
  startDate: Date;
90
94
  endDate: Date;
95
+ pinCode?: string | undefined;
91
96
  }) => Promise<any>;
92
97
  deletePinCodeByKeyId: ({ keyId, accommodationId, }: {
93
98
  keyId: string;
@@ -293,12 +293,12 @@ var SmartAccessAdapter = /** @class */ (function () {
293
293
  });
294
294
  }); };
295
295
  this.createPinCodeForRoom = function (_a) {
296
- var roomId = _a.roomId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate;
296
+ var roomId = _a.roomId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate, _b = _a.pinCode, pinCode = _b === void 0 ? null : _b;
297
297
  return __awaiter(_this, void 0, void 0, function () {
298
298
  var foundProperty, data, parsedProperty, parsedData, pinCodeResult, keyId, pinCodeQuery, lockInfo;
299
- var _b;
300
- return __generator(this, function (_c) {
301
- switch (_c.label) {
299
+ var _c;
300
+ return __generator(this, function (_d) {
301
+ switch (_d.label) {
302
302
  case 0: return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
303
303
  accommodationId: accommodationId,
304
304
  provider: this.PROVIDER_KEY,
@@ -306,7 +306,7 @@ var SmartAccessAdapter = /** @class */ (function () {
306
306
  type: 'room',
307
307
  })];
308
308
  case 1:
309
- foundProperty = _c.sent();
309
+ foundProperty = _d.sent();
310
310
  if (!(foundProperty === null || foundProperty === void 0 ? void 0 : foundProperty.result)) return [3 /*break*/, 4];
311
311
  data = foundProperty.data;
312
312
  parsedProperty = JSON.parse(data);
@@ -317,7 +317,7 @@ var SmartAccessAdapter = /** @class */ (function () {
317
317
  params: {
318
318
  userType: userType,
319
319
  keyType: keyType,
320
- pinCode: null,
320
+ pinCode: pinCode,
321
321
  roomId: parsedProperty.thirdPartyId,
322
322
  accessStartDate: (0, moment_1.default)(startDate)
323
323
  .add(9, 'hours')
@@ -326,7 +326,7 @@ var SmartAccessAdapter = /** @class */ (function () {
326
326
  },
327
327
  })];
328
328
  case 2:
329
- pinCodeResult = _c.sent();
329
+ pinCodeResult = _d.sent();
330
330
  keyId = pinCodeResult.keyId;
331
331
  return [4 /*yield*/, this.callSmartAccessApi({
332
332
  accommodationId: accommodationId,
@@ -334,35 +334,35 @@ var SmartAccessAdapter = /** @class */ (function () {
334
334
  route: "v1/key/".concat(keyId, "/pincode"),
335
335
  })];
336
336
  case 3:
337
- pinCodeQuery = _c.sent();
338
- lockInfo = ((_b = pinCodeQuery === null || pinCodeQuery === void 0 ? void 0 : pinCodeQuery.lockList) === null || _b === void 0 ? void 0 : _b[0]) || {};
337
+ pinCodeQuery = _d.sent();
338
+ lockInfo = ((_c = pinCodeQuery === null || pinCodeQuery === void 0 ? void 0 : pinCodeQuery.lockList) === null || _c === void 0 ? void 0 : _c[0]) || {};
339
339
  return [2 /*return*/, __assign(__assign({}, lockInfo), { pinCode: (lockInfo === null || lockInfo === void 0 ? void 0 : lockInfo.pinCode) || (parsedData === null || parsedData === void 0 ? void 0 : parsedData.masterPinCode), keyId: keyId, pinCodeResult: pinCodeResult })];
340
- case 4: return [2 /*return*/];
340
+ case 4: return [2 /*return*/, {
341
+ error: 'THIRDPARTY_PROPERTY_NOT_FOUND',
342
+ }];
341
343
  }
342
344
  });
343
345
  });
344
346
  };
345
347
  this.modifyPinCodeByKeyId = function (_a) {
346
- var keyId = _a.keyId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate;
348
+ var keyId = _a.keyId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate, pinCode = _a.pinCode;
347
349
  return __awaiter(_this, void 0, void 0, function () {
348
- var pinCodeResult, pinCodeQuery;
350
+ var pinCodeResult, newKeyId, pinCodeQuery;
349
351
  return __generator(this, function (_b) {
350
352
  switch (_b.label) {
351
353
  case 0: return [4 /*yield*/, this.callSmartAccessApi({
352
354
  accommodationId: accommodationId,
353
355
  method: 'put',
354
356
  route: "v1/key/".concat(keyId, "/pincode"),
355
- params: {
356
- userType: userType,
357
- keyType: keyType,
358
- accessStartDate: (0, moment_1.default)(startDate)
357
+ params: __assign({ userType: userType, keyType: keyType, accessStartDate: (0, moment_1.default)(startDate)
359
358
  .add(9, 'hours')
360
- .format('YYYYMMDDHHmm'),
361
- accessEndDate: (0, moment_1.default)(endDate).add(9, 'hours').format('YYYYMMDDHHmm'),
362
- },
359
+ .format('YYYYMMDDHHmm'), accessEndDate: (0, moment_1.default)(endDate).add(9, 'hours').format('YYYYMMDDHHmm') }, (pinCode && {
360
+ pinCode: pinCode,
361
+ })),
363
362
  })];
364
363
  case 1:
365
364
  pinCodeResult = _b.sent();
365
+ newKeyId = pinCodeResult.keyId;
366
366
  return [4 /*yield*/, this.callSmartAccessApi({
367
367
  accommodationId: accommodationId,
368
368
  method: 'get',
@@ -370,7 +370,7 @@ var SmartAccessAdapter = /** @class */ (function () {
370
370
  })];
371
371
  case 2:
372
372
  pinCodeQuery = _b.sent();
373
- return [2 /*return*/, __assign(__assign({}, pinCodeQuery.lockList[0]), { keyId: keyId })];
373
+ return [2 /*return*/, __assign(__assign({}, pinCodeQuery.lockList[0]), { keyId: newKeyId })];
374
374
  }
375
375
  });
376
376
  });
package/lib/index.d.ts CHANGED
@@ -2,6 +2,6 @@ import AmanoKoreaAdapter from './adapters/amanoKorea';
2
2
  import SanhaWingsAdapter from './adapters/sanhaWings';
3
3
  import SmartAccessAdapter from './adapters/smartAccess';
4
4
  import ThemrIoTAdapter from './adapters/themrIoT';
5
- import { NiceParkThirdParty } from './adapters/parking/nicePark';
5
+ import { NiceParkThirdParty, NiceParkingConfig } from './adapters/parking/nicePark';
6
6
  export { default as ParkingThirdPartyCaller } from './adapters/parking/parkingThridPartyCaller';
7
- export { AmanoKoreaAdapter, SanhaWingsAdapter, NiceParkThirdParty, SmartAccessAdapter, ThemrIoTAdapter as TheMRIoTAdapter, };
7
+ export { AmanoKoreaAdapter, SanhaWingsAdapter, NiceParkThirdParty, SmartAccessAdapter, NiceParkingConfig, ThemrIoTAdapter as TheMRIoTAdapter, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.7.4",
3
+ "version": "0.7.6-beta.1",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {