@vendit-dev/thirdparty-adapters 0.7.4 → 0.7.5

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
  };
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, };
@@ -0,0 +1 @@
1
+ export declare function findMinimumNumbersForSum(target: number, numbers: number[]): number[];
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findMinimumNumbersForSum = void 0;
4
+ function findMinimumNumbersForSum(target, numbers) {
5
+ // Sort the numbers array in descending order.
6
+ numbers.sort(function (a, b) { return b - a; });
7
+ var sum = 0;
8
+ var result = [];
9
+ for (var _i = 0, numbers_1 = numbers; _i < numbers_1.length; _i++) {
10
+ var number = numbers_1[_i];
11
+ while (sum + number <= target) {
12
+ sum += number;
13
+ result.push(number);
14
+ }
15
+ // Early exit if the target is reached or exceeded.
16
+ if (sum >= target) {
17
+ break;
18
+ }
19
+ }
20
+ // If the sum is not reached, no solution exists with the given numbers.
21
+ if (sum < target) {
22
+ return [];
23
+ }
24
+ return result;
25
+ }
26
+ exports.findMinimumNumbersForSum = findMinimumNumbersForSum;
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.5",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {