@vendit-dev/thirdparty-adapters 0.7.15 → 0.7.16

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.
@@ -27,7 +27,6 @@ exports.withAsyncBandwidth = exports.refineReservationData = exports.formattedPa
27
27
  var fast_xml_parser_1 = require("fast-xml-parser");
28
28
  var moment_1 = __importDefault(require("moment"));
29
29
  var tl_lincoln_types_1 = require("./tl-lincoln.types");
30
- var function_1 = require("../../utils/function");
31
30
  var tl_lincoln_ota_1 = require("../../types/tl-lincoln.ota");
32
31
  function jsonToXml(json) {
33
32
  var options = {
@@ -119,6 +118,28 @@ var getMealConditionText = function (_mealCondition) {
119
118
  return '조식 없음';
120
119
  }
121
120
  };
121
+ function groupByRoomWithTotalCounts(roomAndRoomRateInformations, totalRoomCount) {
122
+ var groupedRooms = Array(totalRoomCount).fill([]);
123
+ return roomAndRoomRateInformations.reduce(function (acc, curr) {
124
+ var RoomTypeCode = curr.RoomInformation.RoomTypeCode, RoomDate = curr.RoomRateInformation.RoomDate;
125
+ var existingRooms = acc.find(function (groupedRooms) {
126
+ var _a, _b;
127
+ return groupedRooms.length > 0 &&
128
+ ((_b = (_a = groupedRooms[0]) === null || _a === void 0 ? void 0 : _a.RoomInformation) === null || _b === void 0 ? void 0 : _b.RoomTypeCode) === RoomTypeCode &&
129
+ !groupedRooms.some(function (room) { return room.RoomRateInformation.RoomDate === RoomDate; });
130
+ });
131
+ if (existingRooms) {
132
+ existingRooms.push(curr);
133
+ }
134
+ else {
135
+ var emptyRoomIndex = acc.findIndex(function (groupedRoom) { return groupedRoom.length === 0; });
136
+ if (emptyRoomIndex !== -1) {
137
+ acc[emptyRoomIndex] = [curr];
138
+ }
139
+ }
140
+ return acc;
141
+ }, groupedRooms);
142
+ }
122
143
  var formattedNameForMealCondition = function (mealCondition, specificMealCondition) {
123
144
  var _a;
124
145
  return "".concat(getMealConditionText(mealCondition)).concat(((_a = getSpecificMealConditionText(specificMealCondition)) === null || _a === void 0 ? void 0 : _a.length) > 0
@@ -166,20 +187,20 @@ function formatPhoneNumber(text) {
166
187
  return onlyNumberText ? "010".concat(onlyNumberText.slice(-8)) : '';
167
188
  }
168
189
  var makePaymentInfo = function (_a) {
169
- var datas = _a.datas, basicRateInformation = _a.basicRateInformation, basicInformation = _a.basicInformation, reservationType = _a.reservationType, CheckInDate = _a.CheckInDate, OptionList = _a.OptionList, roomsSortedByDate = _a.roomsSortedByDate;
190
+ var datas = _a.datas, basicRateInformation = _a.basicRateInformation, basicInformation = _a.basicInformation, reservationType = _a.reservationType, OptionList = _a.OptionList;
170
191
  return datas.reduce(function (paymentInput, _a) {
171
192
  var _b, _c, _d;
172
193
  var RoomInfo = _a.RoomInformation, RoomRateInformation = _a.RoomRateInformation;
173
- var roomAmount = (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomRate)
174
- || ((RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerMaleRate) || 0)
175
- * (RoomInfo.RoomPaxMaleCount || 0)
176
- + ((RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerFemaleRate)
177
- || (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerMaleRate)
178
- || 0)
179
- * (RoomInfo.RoomPaxFemaleCount || 0)
180
- || (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomRate)
181
- || basicRateInformation.TotalAccommodationCharge
182
- || 0;
194
+ var roomAmount = (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomRate) ||
195
+ ((RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerMaleRate) || 0) *
196
+ (RoomInfo.RoomPaxMaleCount || 0) +
197
+ ((RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerFemaleRate) ||
198
+ (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.PerMaleRate) ||
199
+ 0) *
200
+ (RoomInfo.RoomPaxFemaleCount || 0) ||
201
+ (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomRate) ||
202
+ basicRateInformation.TotalAccommodationCharge ||
203
+ 0;
183
204
  paymentInput.amount += roomAmount;
184
205
  (_b = paymentInput.segments) === null || _b === void 0 ? void 0 : _b.push({
185
206
  amount: roomAmount,
@@ -187,8 +208,8 @@ var makePaymentInfo = function (_a) {
187
208
  referenceType: 'RESERVATION',
188
209
  referenceSubType: reservationType,
189
210
  });
190
- if (basicInformation.MealCondition !== 'Other'
191
- && basicInformation.MealCondition !== 'WithoutMeal') {
211
+ if (basicInformation.MealCondition !== 'Other' &&
212
+ basicInformation.MealCondition !== 'WithoutMeal') {
192
213
  paymentInput.amount += (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomServiceFee) || 0;
193
214
  (_c = paymentInput.segments) === null || _c === void 0 ? void 0 : _c.push({
194
215
  amount: (RoomRateInformation === null || RoomRateInformation === void 0 ? void 0 : RoomRateInformation.TotalPerRoomServiceFee) || 0,
@@ -208,9 +229,9 @@ var makePaymentInfo = function (_a) {
208
229
  return Object.assign(paymentInput, {
209
230
  reservationType: reservationType,
210
231
  type: 'platform',
211
- externalRoomTypeCode: roomsSortedByDate[0].RoomInformation.NetRmTypeGroupCode,
212
- externalRoomTypeName: roomsSortedByDate[0].RoomInformation.RoomTypeName,
213
- useStartAt: "".concat(CheckInDate).concat((basicInformation === null || basicInformation === void 0 ? void 0 : basicInformation.CheckInTime)
232
+ externalRoomTypeCode: datas[0].RoomInformation.NetRmTypeGroupCode,
233
+ externalRoomTypeName: datas[0].RoomInformation.RoomTypeName,
234
+ useStartAt: "".concat(datas[0].RoomRateInformation.RoomDate).concat((basicInformation === null || basicInformation === void 0 ? void 0 : basicInformation.CheckInTime)
214
235
  ? " ".concat(basicInformation === null || basicInformation === void 0 ? void 0 : basicInformation.CheckInTime)
215
236
  : ''),
216
237
  });
@@ -232,11 +253,11 @@ var refineReservationData = function (infoTravelXML) {
232
253
  var isGroupReservation = BasicInformation.TotalRoomCount > 1;
233
254
  var RisaplsCommonInformation = RisaplsInformation.RisaplsCommonInformation, AgentNativeInformation = RisaplsInformation.AgentNativeInformation;
234
255
  var RoomAndRoomRateInformation = RisaplsCommonInformation.RoomAndRoomRateInformation, Allotment = RisaplsCommonInformation.Allotment, Member = RisaplsCommonInformation.Member, OtherInfo = RisaplsCommonInformation.OtherInfo, Basic = RisaplsCommonInformation.Basic, BasicRate = RisaplsCommonInformation.BasicRate, Option = RisaplsCommonInformation.Option;
235
- var isFullyPaid = !!((_a = AgentNativeInformation === null || AgentNativeInformation === void 0 ? void 0 : AgentNativeInformation.Extendmytrip) === null || _a === void 0 ? void 0 : _a.SettlementDiv)
236
- && !((_b = AgentNativeInformation === null || AgentNativeInformation === void 0 ? void 0 : AgentNativeInformation.Extend) === null || _b === void 0 ? void 0 : _b.AmountClaimed)
237
- && (BasicRateInformation === null || BasicRateInformation === void 0 ? void 0 : BasicRateInformation.Payment) !== 'Hotel Collect';
256
+ var isFullyPaid = !!((_a = AgentNativeInformation === null || AgentNativeInformation === void 0 ? void 0 : AgentNativeInformation.Extendmytrip) === null || _a === void 0 ? void 0 : _a.SettlementDiv) &&
257
+ !((_b = AgentNativeInformation === null || AgentNativeInformation === void 0 ? void 0 : AgentNativeInformation.Extend) === null || _b === void 0 ? void 0 : _b.AmountClaimed) &&
258
+ (BasicRateInformation === null || BasicRateInformation === void 0 ? void 0 : BasicRateInformation.Payment) !== 'Hotel Collect';
238
259
  var roomAndRoomRateInformations = (0, tl_lincoln_types_1.makeArray)(RoomAndRoomRateInformation);
239
- var groupedRooms = (0, function_1.groupBy)(roomAndRoomRateInformations, 'RoomInformation.RoomByRoomConfirmationNumber');
260
+ var groupedRooms = groupByRoomWithTotalCounts(roomAndRoomRateInformations, BasicInformation.TotalRoomCount);
240
261
  var status = getReservationStatusFromDataClassification(TransactionType.DataClassification);
241
262
  var useStartAt = "".concat(BasicInformation.CheckInDate).concat((BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.CheckInTime) ? " ".concat(BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.CheckInTime) : '');
242
263
  var useExpireAt = "".concat((0, moment_1.default)(BasicInformation.CheckInDate)
@@ -255,9 +276,9 @@ var refineReservationData = function (infoTravelXML) {
255
276
  name: BasicInformation.GuestOrGroupNameKanjiName,
256
277
  email: Member === null || Member === void 0 ? void 0 : Member.UserMailAddr,
257
278
  reservedBy: SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName,
258
- memo: "".concat((Member === null || Member === void 0 ? void 0 : Member.UserKana)
259
- || (Member === null || Member === void 0 ? void 0 : Member.UserName)
260
- || "".concat(BasicInformation.GuestOrGroupNameKanjiName), " ").concat(BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.PackagePlanName, "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.GuestRequest)
279
+ memo: "".concat((Member === null || Member === void 0 ? void 0 : Member.UserKana) ||
280
+ (Member === null || Member === void 0 ? void 0 : Member.UserName) ||
281
+ "".concat(BasicInformation.GuestOrGroupNameKanjiName), " ").concat(BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.PackagePlanName, "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.GuestRequest)
261
282
  ? "[\uC694\uCCAD\uC0AC\uD56D]\n".concat(OtherInfo.GuestRequest)
262
283
  : '', "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.AdditionalInformation)
263
284
  ? "[\uCD94\uAC00\uC815\uBCF4]\n".concat(OtherInfo.AdditionalInformation)
@@ -276,35 +297,31 @@ var refineReservationData = function (infoTravelXML) {
276
297
  useStartAt: useStartAt,
277
298
  platform: tl_lincoln_ota_1.TL_LINCOLN_TO_VENDIT_OTA_MAP[(SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) || 'ANONYMOUS'] || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName),
278
299
  externalPlatformCode: SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCode,
279
- externalPlatformName: (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName)
280
- || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeName),
300
+ externalPlatformName: (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) ||
301
+ (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeName),
281
302
  },
282
- reservations: Object.keys(groupedRooms).map(function (key, index) {
283
- var _a, _b, _c, _d;
284
- var datas = groupedRooms[key];
303
+ reservations: groupedRooms.map(function (key, index) {
304
+ var _a, _b, _c, _d, _e;
305
+ var datas = groupedRooms[index];
285
306
  var roomsSortedByDate = datas.sort(function (a, b) {
286
- return new Date(a.RoomRateInformation.RoomDate).valueOf()
287
- - new Date(b.RoomRateInformation.RoomDate).valueOf();
307
+ return new Date(a.RoomRateInformation.RoomDate).valueOf() -
308
+ new Date(b.RoomRateInformation.RoomDate).valueOf();
288
309
  });
289
- var reservationType = Number(Allotment.UseDiv) === 1
290
- && BasicInformation.CheckInDate === BasicInformation.CheckOutDate
310
+ var reservationType = Number(Allotment.UseDiv) === 1 &&
311
+ BasicInformation.CheckInDate === BasicInformation.CheckOutDate
291
312
  ? 'rent'
292
313
  : 'lodge';
293
314
  var CheckInDate = roomsSortedByDate[0].RoomRateInformation.RoomDate;
294
315
  var CheckOutDate = (_a = (0, moment_1.default)(CheckInDate)
295
316
  .add(BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.Nights, 'days')) === null || _a === void 0 ? void 0 : _a.format('YYYY-MM-DD');
296
- var OptionList = Option
297
- ? (0, tl_lincoln_types_1.makeArray)(Option)
298
- : [];
317
+ var OptionList = Option ? (0, tl_lincoln_types_1.makeArray)(Option) : [];
299
318
  var DepositList = (BasicRate === null || BasicRate === void 0 ? void 0 : BasicRate.DepositList) && (0, tl_lincoln_types_1.makeArray)(BasicRate.DepositList);
300
319
  var paymentInfo = makePaymentInfo({
301
320
  datas: datas,
302
321
  basicRateInformation: BasicRateInformation,
303
322
  basicInformation: BasicInformation,
304
323
  reservationType: reservationType,
305
- CheckInDate: CheckInDate,
306
324
  OptionList: OptionList,
307
- roomsSortedByDate: roomsSortedByDate,
308
325
  });
309
326
  return {
310
327
  useStartAt: "".concat(CheckInDate).concat((BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.CheckInTime)
@@ -313,27 +330,31 @@ var refineReservationData = function (infoTravelXML) {
313
330
  useExpireAt: "".concat(CheckOutDate).concat((BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.CheckOutTime)
314
331
  ? " ".concat(BasicInformation === null || BasicInformation === void 0 ? void 0 : BasicInformation.CheckOutTime)
315
332
  : ''),
316
- sleeps: (_c = (_b = roomsSortedByDate[0]) === null || _b === void 0 ? void 0 : _b.RoomInformation) === null || _c === void 0 ? void 0 : _c.PerRoomPaxCount,
317
- guestName: "".concat(BasicInformation.GuestOrGroupNameSingleByte
318
- || BasicInformation.GuestOrGroupNameKanjiName
319
- || 'Anonymous').concat(isGroupReservation ? " ".concat(index + 1) : ''),
333
+ sleeps: isGroupReservation
334
+ ? (BasicInformation.GrandTotalPaxCount || 0) /
335
+ BasicInformation.TotalRoomCount ||
336
+ ((_b = datas[0].RoomInformation) === null || _b === void 0 ? void 0 : _b.PerRoomPaxCount)
337
+ : (_d = (_c = roomsSortedByDate[0]) === null || _c === void 0 ? void 0 : _c.RoomInformation) === null || _d === void 0 ? void 0 : _d.PerRoomPaxCount,
338
+ guestName: "".concat(BasicInformation.GuestOrGroupNameSingleByte ||
339
+ BasicInformation.GuestOrGroupNameKanjiName ||
340
+ 'Anonymous').concat(isGroupReservation ? " ".concat(index + 1) : ''),
320
341
  externalPlatformCode: SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCode,
321
- externalPlatformName: (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName)
322
- || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeName),
342
+ externalPlatformName: (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) ||
343
+ (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeName),
323
344
  cmsOtaNumber: "".concat(BasicInformation.TravelAgencyBookingNumber).concat(isGroupReservation ? "-v".concat(index + 1) : ''),
324
- cmsProductName: roomsSortedByDate[0].RoomInformation.RoomTypeName
325
- || BasicInformation.PackagePlanName,
345
+ cmsProductName: roomsSortedByDate[0].RoomInformation.RoomTypeName ||
346
+ BasicInformation.PackagePlanName,
326
347
  platform: tl_lincoln_ota_1.TL_LINCOLN_TO_VENDIT_OTA_MAP[(SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) || 'ANONYMOUS'] || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName),
327
- otaNumber: "".concat(tl_lincoln_ota_1.TL_LINCOLN_TO_VENDIT_OTA_MAP[(SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) || 'ANONYMOUS'] || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName), "|").concat((_d = "".concat(BasicInformation.TravelAgencyBookingNumber)) === null || _d === void 0 ? void 0 : _d.slice(-4)),
348
+ otaNumber: "".concat(tl_lincoln_ota_1.TL_LINCOLN_TO_VENDIT_OTA_MAP[(SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName) || 'ANONYMOUS'] || (SalesOfficeInformation === null || SalesOfficeInformation === void 0 ? void 0 : SalesOfficeInformation.SalesOfficeCompanyName), "|").concat((_e = "".concat(BasicInformation.TravelAgencyBookingNumber)) === null || _e === void 0 ? void 0 : _e.slice(-4)),
328
349
  externalRoomTypeCode: roomsSortedByDate[0].RoomInformation.NetRmTypeGroupCode,
329
350
  externalRoomTypeName: roomsSortedByDate[0].RoomInformation.RoomTypeName,
330
351
  type: reservationType,
331
352
  phone: formatPhoneNumber("".concat((Member === null || Member === void 0 ? void 0 : Member.UserTel) || Basic.PhoneNumber || '')),
332
353
  status: status,
333
- memoContent: "".concat((Member === null || Member === void 0 ? void 0 : Member.UserKana)
334
- || (Member === null || Member === void 0 ? void 0 : Member.UserName)
335
- || "".concat(BasicInformation.GuestOrGroupNameKanjiName), " ").concat(roomsSortedByDate[0].RoomInformation.RoomTypeName
336
- || BasicInformation.PackagePlanName, "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.GuestRequest)
354
+ memoContent: "".concat((Member === null || Member === void 0 ? void 0 : Member.UserKana) ||
355
+ (Member === null || Member === void 0 ? void 0 : Member.UserName) ||
356
+ "".concat(BasicInformation.GuestOrGroupNameKanjiName), " ").concat(roomsSortedByDate[0].RoomInformation.RoomTypeName ||
357
+ BasicInformation.PackagePlanName, "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.GuestRequest)
337
358
  ? "[\uC694\uCCAD\uC0AC\uD56D]\n".concat(OtherInfo.GuestRequest)
338
359
  : '', "\n").concat((OtherInfo === null || OtherInfo === void 0 ? void 0 : OtherInfo.AdditionalInformation)
339
360
  ? "[\uCD94\uAC00\uC815\uBCF4]\n".concat(OtherInfo.AdditionalInformation)
@@ -343,8 +364,8 @@ var refineReservationData = function (infoTravelXML) {
343
364
  paymentInfo: Object.assign(paymentInfo, !isFullyPaid && {
344
365
  amount: (DepositList === null || DepositList === void 0 ? void 0 : DepositList.reduce(function (acc, deposit) { return acc + ((deposit === null || deposit === void 0 ? void 0 : deposit.DepositAmount) || 0); }, 0)) || 0,
345
366
  isFullyPaid: false,
346
- outstandingAmount: paymentInfo.amount
347
- - ((DepositList === null || DepositList === void 0 ? void 0 : DepositList.reduce(function (acc, deposit) { return acc + ((deposit === null || deposit === void 0 ? void 0 : deposit.DepositAmount) || 0); }, 0)) || 0),
367
+ outstandingAmount: paymentInfo.amount -
368
+ ((DepositList === null || DepositList === void 0 ? void 0 : DepositList.reduce(function (acc, deposit) { return acc + ((deposit === null || deposit === void 0 ? void 0 : deposit.DepositAmount) || 0); }, 0)) || 0),
348
369
  }),
349
370
  };
350
371
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.7.15",
3
+ "version": "0.7.16",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {