turf-common 1.4.2-beta.8 → 3.0.0

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.
Files changed (64) hide show
  1. package/README.md +20 -20
  2. package/build/jest.config.js +2 -1
  3. package/build/src/@model.d.ts +1 -0
  4. package/build/src/@model.js +1 -0
  5. package/build/src/enums/booking-history-operation-type.enum.d.ts +4 -1
  6. package/build/src/enums/booking-history-operation-type.enum.js +3 -0
  7. package/build/src/enums/organization-status.enum.d.ts +4 -0
  8. package/build/src/enums/organization-status.enum.js +6 -1
  9. package/build/src/enums/transaction-type.enum.d.ts +2 -1
  10. package/build/src/enums/transaction-type.enum.js +1 -0
  11. package/build/src/interface/api/booking-availablity-by-pitch.interface.d.ts +1 -0
  12. package/build/src/interface/api/booking-pending-payment-writeoff.interface.d.ts +10 -0
  13. package/build/src/interface/api/booking-pending-payment-writeoff.interface.js +2 -0
  14. package/build/src/interface/api/create-recurring-slot-booking.interface.d.ts +4 -1
  15. package/build/src/interface/api/create-user.interface.d.ts +1 -1
  16. package/build/src/interface/api/get-availability-by-turf.interface.d.ts +1 -0
  17. package/build/src/interface/api/get-booking-by-organization-id.interface.d.ts +1 -1
  18. package/build/src/interface/api/get-booking-history.interface.d.ts +1 -0
  19. package/build/src/interface/api/get-collection.interface.d.ts +1 -1
  20. package/build/src/interface/api/get-organization-configuration.interface.d.ts +8 -0
  21. package/build/src/interface/api/get-organization-configuration.interface.js +2 -0
  22. package/build/src/interface/api/index.d.ts +3 -0
  23. package/build/src/interface/api/index.js +3 -0
  24. package/build/src/interface/api/login-response.interface.d.ts +4 -1
  25. package/build/src/interface/api/one-slot-booking.interface.d.ts +2 -0
  26. package/build/src/interface/api/staff-member-list.interface.d.ts +1 -1
  27. package/build/src/interface/api/update-organization-configuration.interface.d.ts +6 -0
  28. package/build/src/interface/api/update-organization-configuration.interface.js +2 -0
  29. package/build/src/interface/api/update-recurring-booking.interface.d.ts +1 -0
  30. package/build/src/interface/api/update-staff-member.interface.d.ts +1 -1
  31. package/build/src/interface/entity/organization-entity.interface.d.ts +15 -3
  32. package/build/src/interface/entity/user-entity.interface.d.ts +6 -6
  33. package/build/src/interface/get-booking-by-id.interface.d.ts +2 -2
  34. package/build/src/interface/model/booking-details-model.interface.d.ts +8 -0
  35. package/build/src/interface/user-entity-essential-info.interface.d.ts +1 -1
  36. package/build/src/models/booking-code-model.d.ts +16 -2
  37. package/build/src/models/booking-code-model.js +83 -40
  38. package/build/src/models/charge-model.d.ts +2 -0
  39. package/build/src/models/charge-model.js +41 -11
  40. package/build/src/models/entity/booking-details-model.d.ts +2 -1
  41. package/build/src/models/entity/booking-details-model.js +19 -0
  42. package/build/src/models/entity/booking-entity-model.d.ts +1 -0
  43. package/build/src/models/entity/booking-entity-model.js +3 -0
  44. package/build/src/models/entity/user-model.d.ts +6 -6
  45. package/build/src/models/time-slot-model.d.ts +1 -0
  46. package/build/src/models/time-slot-model.js +3 -0
  47. package/build/src/models/turf-availability-model.d.ts +18 -3
  48. package/build/src/models/turf-availability-model.js +60 -3
  49. package/build/src/models/weekday-time-slot-model.d.ts +12 -0
  50. package/build/src/models/weekday-time-slot-model.js +30 -0
  51. package/build/src/utils/constant.d.ts +3 -0
  52. package/build/src/utils/constant.js +4 -1
  53. package/build/src/utils/date-util.d.ts +8 -1
  54. package/build/src/utils/date-util.js +22 -3
  55. package/build/tests/booking-code/method.spec.d.ts +1 -0
  56. package/build/tests/booking-code/method.spec.js +11 -0
  57. package/build/tests/unit/charges/discount-relative/basic.spec.d.ts +1 -0
  58. package/build/tests/unit/charges/discount-relative/basic.spec.js +209 -0
  59. package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.d.ts +1 -0
  60. package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.js +208 -0
  61. package/build/tests/unit/charges/extension/basic.spec.d.ts +1 -0
  62. package/build/tests/unit/charges/extension/basic.spec.js +215 -0
  63. package/build/tests/unit/pricing-plan/basic-scenario.spec.js +1 -1
  64. package/package.json +17 -6
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.BookingCode = void 0;
15
4
  var time_slot_model_1 = require("./time-slot-model");
@@ -60,7 +49,7 @@ var BookingCode = /** @class */ (function () {
60
49
  };
61
50
  /**
62
51
  *
63
- * @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
52
+ * @returns ['00000030','00300100','01000130']: string[] - List of half hour time slot codes between start time & end time inclusive
64
53
  * @example fromTime: 0000; toTime: 0130
65
54
  * // returns ['00000030','00300100','01000130']
66
55
  */
@@ -102,9 +91,54 @@ var BookingCode = /** @class */ (function () {
102
91
  BookingCode.prototype.getDateWithFromTimeCode = function () {
103
92
  return "".concat(this.dateCode).concat(this.fromTimeCode);
104
93
  };
94
+ BookingCode.prototype.getDateWithToTimeCode = function () {
95
+ return "".concat(this.dateCode).concat(this.toTimeCode);
96
+ };
105
97
  BookingCode.prototype.getCodeWithoutTurfCode = function () {
106
98
  return "".concat(this.dateCode).concat(this.slot).concat(this.pitchCode);
107
99
  };
100
+ BookingCode.prototype.getPriceByPriceEntities = function (priceEntities) {
101
+ var halfHourTimeRangeCodes = this.getHalfHourTimeRangeCodes();
102
+ var weekDay = this.getWeekday();
103
+ var monthCode = this.getMonthCode();
104
+ var price = 0;
105
+ for (var _i = 0, halfHourTimeRangeCodes_1 = halfHourTimeRangeCodes; _i < halfHourTimeRangeCodes_1.length; _i++) {
106
+ var halfHourTimeRangeCode = halfHourTimeRangeCodes_1[_i];
107
+ price +=
108
+ priceEntities[monthCode + weekDay][halfHourTimeRangeCode] < 0 ? 0 : priceEntities[monthCode + weekDay][halfHourTimeRangeCode];
109
+ }
110
+ return price;
111
+ };
112
+ BookingCode.prototype.getToDate = function () {
113
+ return date_util_1.dateUtilService.convertStringToDate(this.getDateWithToTimeCode(), "yyMMddHHmm");
114
+ };
115
+ BookingCode.prototype.isAcrossDate = function () {
116
+ return this.fromTimeCode > this.toTimeCode;
117
+ };
118
+ BookingCode.prototype.isModificationAllowed = function (delayInMinutes) {
119
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_MODIFICATION_DELAY_IN_MINUTES; }
120
+ var dateWithToTimeCode = this.getDateWithToTimeCode();
121
+ // If last four digits of dateWithToTimeCode is 2400, then replace it with 2359
122
+ if (dateWithToTimeCode.slice(-4) === _utils_1.END_OF_DAY_TIME_CODE) {
123
+ dateWithToTimeCode = dateWithToTimeCode.slice(0, -4) + "2359";
124
+ }
125
+ var toDate = date_util_1.dateUtilService.convertStringToDate(dateWithToTimeCode, "yyMMddHHmm");
126
+ var bookingToDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(toDate, delayInMinutes + (this.isAcrossDate() ? 24 * 60 : 0));
127
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
128
+ return bookingToDateTimeWithDelay > currentTime;
129
+ };
130
+ BookingCode.prototype.isDeletionAllowed = function (delayInMinutes) {
131
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_DELETION_DELAY_IN_MINUTES; }
132
+ var bookingFromDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(date_util_1.dateUtilService.convertStringToDate(this.getDateWithFromTimeCode(), "yyMMddHHmm"), delayInMinutes);
133
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
134
+ return bookingFromDateTimeWithDelay > currentTime;
135
+ };
136
+ BookingCode.prototype.isCreationAllowed = function (delayInMinutes) {
137
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_DELAY_IN_MINUTES; }
138
+ var bookingFromDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(date_util_1.dateUtilService.convertStringToDate(this.getDateWithFromTimeCode(), "yyMMddHHmm"), delayInMinutes);
139
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
140
+ return bookingFromDateTimeWithDelay > currentTime;
141
+ };
108
142
  BookingCode.sortByCode = function (bookingCodes) {
109
143
  bookingCodes.sort(function (_a, _b) {
110
144
  var code1 = _a.code;
@@ -221,26 +255,17 @@ var BookingCode = /** @class */ (function () {
221
255
  }
222
256
  };
223
257
  //---------------------
224
- BookingCode.previousTimeChecker = function (fromTime, fromDate, index) {
225
- var now = new Date();
226
- this.convertToDate(fromDate.toString());
227
- var delayInBooking = 15;
228
- if (this.convertToDate(fromDate.toString()) > now) {
229
- return; //do nothing if fromDate is in future
230
- }
231
- else if (this.convertToDate(fromDate.toString()) <= now) {
232
- now.setMinutes(now.getMinutes() - delayInBooking); // 15minutes buffer for late bookings
233
- var options = {
234
- timeZone: "Asia/Kolkata",
235
- };
236
- var timeFormat = new Intl.DateTimeFormat("en-US", __assign(__assign({}, options), { hour: "2-digit", minute: "2-digit", hour12: false }));
237
- var currentTimeObj = timeFormat.format(now).replace(/:/g, "");
238
- if (fromTime < currentTimeObj) {
239
- throw new app_badrequest_exception_1.AppBadRequestException({
240
- key: "slot.".concat(index),
241
- message: ["Booking time should be in future"],
242
- });
243
- }
258
+ BookingCode.previousTimeChecker = function (fromTime, fromDate, index, bookingDelayInMinutes, date) {
259
+ if (bookingDelayInMinutes === void 0) { bookingDelayInMinutes = _utils_1.DEFAULT_BOOKING_DELAY_IN_MINUTES; }
260
+ if (date === void 0) { date = date_util_1.dateUtilService.getIndianDate(); }
261
+ var now = date;
262
+ var bookingDate = date_util_1.dateUtilService.convertStringToDate(fromDate.toString() + fromTime, "yyMMddHHmm");
263
+ var difference = bookingDate.getTime() - now.getTime() + bookingDelayInMinutes * 60 * 1000;
264
+ if (difference < 0) {
265
+ throw new app_badrequest_exception_1.AppBadRequestException({
266
+ key: "slot.".concat(index),
267
+ message: ["Invalid booking time. Booking time should be within ".concat(bookingDelayInMinutes, " minutes from current time")],
268
+ });
244
269
  }
245
270
  };
246
271
  //---------------------
@@ -303,6 +328,11 @@ var BookingCode = /** @class */ (function () {
303
328
  .toString()
304
329
  .padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
305
330
  };
331
+ BookingCode.getMonthCode = function (date) {
332
+ return parseInt("".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
333
+ .toString()
334
+ .padStart(2, "0")));
335
+ };
306
336
  /**
307
337
  * Returns list of month codes (YYMM) in the Date range inclusive
308
338
  * @param {Date} from - Start Date
@@ -313,14 +343,18 @@ var BookingCode = /** @class */ (function () {
313
343
  from = new Date(from.getTime());
314
344
  to = new Date(to.getTime());
315
345
  var monthCodes = [];
316
- while (from < to) {
317
- var fromDateCode = BookingCode.getDateCode(from);
318
- monthCodes.push(parseInt("".concat(fromDateCode.slice(0, 4))));
319
- from.setMonth(from.getMonth() + 1);
320
- }
321
- var toDateCode = BookingCode.getDateCode(to);
322
- if (!monthCodes.includes(parseInt("".concat(toDateCode.slice(0, 4))))) {
323
- monthCodes.push(parseInt("".concat(toDateCode.slice(0, 4))));
346
+ var fromMonthCode = BookingCode.getMonthCode(from);
347
+ var toMonthCode = BookingCode.getMonthCode(to);
348
+ var currentMonthCode = fromMonthCode;
349
+ while (currentMonthCode <= toMonthCode) {
350
+ monthCodes.push(currentMonthCode);
351
+ // Change of year handling
352
+ if (currentMonthCode % 100 === 12) {
353
+ currentMonthCode = currentMonthCode + 100 - 11;
354
+ }
355
+ else {
356
+ currentMonthCode = currentMonthCode + 1;
357
+ }
324
358
  }
325
359
  return monthCodes;
326
360
  };
@@ -608,6 +642,15 @@ var BookingCode = /** @class */ (function () {
608
642
  this.pitchNumber === nextBookingCode.pitchNumber &&
609
643
  this.turfId === nextBookingCode.turfId);
610
644
  };
645
+ BookingCode.getInstanceByComponents = function (turfId, pitchCode, dateCode, fromTimeCode, toTimeCode, priceCsv) {
646
+ return new BookingCode("".concat(turfId.toString().padStart(4, "0")).concat(dateCode.toString().padStart(6, "0")).concat(fromTimeCode).concat(toTimeCode).concat(pitchCode.toString().padStart(2, "0")), priceCsv);
647
+ };
648
+ BookingCode.prototype.isTimeSlotContinuous = function (that) {
649
+ return this.toTimeCode == that.fromTimeCode &&
650
+ this.pitchNumber == that.pitchNumber &&
651
+ this.turfId == that.turfId &&
652
+ this.dateCode == that.dateCode;
653
+ };
611
654
  /**
612
655
  * Extracts the numeric part of a bookingCode, excluding a predefined deleted slot separator.
613
656
  *
@@ -1,3 +1,4 @@
1
+ import { BookingCode } from "./booking-code-model";
1
2
  import { IBookingModification } from "../types/booking-modification.type";
2
3
  import { ModificationDiscountPolicy } from "../enums/modification-discount-policy.enum";
3
4
  import { IChargeModel } from "../interface/model/charge-model.interface";
@@ -27,6 +28,7 @@ export declare class ChargesModel implements IChargeModel {
27
28
  private modifyMove;
28
29
  clone(): ChargesModel;
29
30
  private modifyDelete;
31
+ extension(extensionBookingCode: BookingCode): ChargesModel;
30
32
  static getInstance(chargeData: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
31
33
  getTotalAmount(): number;
32
34
  getPaymentStatus(): "Refund" | "Paid" | "Pending";
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.ChargesModel = void 0;
4
15
  var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
@@ -9,15 +20,15 @@ var ChargesModel = /** @class */ (function () {
9
20
  this.initialBookingGrossAmount = initialGrossAmount;
10
21
  this.amountPaid = paidAmount;
11
22
  this.couponCode = couponCode;
23
+ this.totalBookingHours = totalBookingHours;
24
+ this.discountPolicy = discountPolicy;
12
25
  this.additionalBookingGrossAmount = 0;
13
26
  this.cancelledBookingGrossAmount = 0;
14
27
  this.totalCancellationCharges = 0;
15
28
  this.refundPayable = 0;
16
29
  this.totalRefundedAmount = 0;
17
- this.totalBookingHours = totalBookingHours;
18
30
  this.netTotal = this.getNetAmount();
19
31
  this.amountPayable = this.getPayableRefundAmount();
20
- this.discountPolicy = discountPolicy;
21
32
  }
22
33
  ChargesModel.prototype.getGrossAmount = function () {
23
34
  return (this.initialBookingGrossAmount +
@@ -35,6 +46,7 @@ var ChargesModel = /** @class */ (function () {
35
46
  this.cancelledBookingGrossAmount > 0) {
36
47
  this.couponCode = "";
37
48
  }
49
+ // console.log("getDiscountAmount", this.couponCode);
38
50
  return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount(), false, this.totalBookingHours);
39
51
  };
40
52
  ChargesModel.prototype.getPayableRefundAmount = function () {
@@ -102,10 +114,6 @@ var ChargesModel = /** @class */ (function () {
102
114
  };
103
115
  ChargesModel.prototype.modify = function (bookingModification) {
104
116
  var oldBookingCode = bookingModification.oldBookingCode, newBookingCode = bookingModification.newBookingCode, cancellationUnit = bookingModification.cancellationUnit;
105
- // this.totalBookingHours =
106
- // this.totalBookingHours -
107
- // oldBookingCode.getTotalTime("hr") +
108
- // (newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
109
117
  if (!newBookingCode) {
110
118
  return this.modifyDelete(oldBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
111
119
  }
@@ -150,9 +158,7 @@ var ChargesModel = /** @class */ (function () {
150
158
  (newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
151
159
  var newChargeModel = this.clone();
152
160
  newChargeModel.totalBookingHours = newTotalBookingHours;
153
- newChargeModel.couponCode = "";
154
161
  var costDifference = oldBookingCode.getCost() - newBookingCode.getCost();
155
- // console.log(`costDifference ${costDifference}`);
156
162
  newChargeModel.cancelledBookingGrossAmount += costDifference;
157
163
  var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, costDifference);
158
164
  // console.log(`cancellationCharges ${cancellationCharges}`);
@@ -208,7 +214,6 @@ var ChargesModel = /** @class */ (function () {
208
214
  var newTotalBookingHours = this.totalBookingHours - bookingCode.getTotalTime("hr");
209
215
  var newChargeModel = this.clone();
210
216
  newChargeModel.totalBookingHours = newTotalBookingHours;
211
- newChargeModel.couponCode = "";
212
217
  var costDifference = bookingCode.getCost();
213
218
  newChargeModel.cancelledBookingGrossAmount += costDifference;
214
219
  var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, costDifference);
@@ -224,10 +229,35 @@ var ChargesModel = /** @class */ (function () {
224
229
  }
225
230
  return newChargeModel;
226
231
  };
232
+ ChargesModel.prototype.extension = function (extensionBookingCode) {
233
+ var newTotalBookingHours = this.totalBookingHours + (extensionBookingCode ? extensionBookingCode.getTotalTime("hr") : 0);
234
+ var newChargeModel = this.clone();
235
+ newChargeModel.totalBookingHours = newTotalBookingHours;
236
+ newChargeModel.additionalBookingGrossAmount += extensionBookingCode.getCost();
237
+ newChargeModel.netTotal = newChargeModel.getNetAmount();
238
+ newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
239
+ // console.log(newChargeModel.payableAmount);
240
+ if (newChargeModel.amountPayable > 0) {
241
+ newChargeModel.refundPayable = 0;
242
+ }
243
+ else {
244
+ newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
245
+ newChargeModel.amountPayable = 0;
246
+ }
247
+ return newChargeModel;
248
+ };
227
249
  ChargesModel.getInstance = function (chargeData, discountPolicy) {
228
250
  if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
229
- var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
230
- Object.assign(chargesModel, chargeData);
251
+ var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, parseFloat(chargeData.totalBookingHours.toString()), discountPolicy);
252
+ var initialBookingGrossAmount = chargeData.initialBookingGrossAmount, amountPaid = chargeData.amountPaid, couponCode = chargeData.couponCode, totalBookingHours = chargeData.totalBookingHours, rest = __rest(chargeData, ["initialBookingGrossAmount", "amountPaid", "couponCode", "totalBookingHours"]);
253
+ chargesModel.additionalBookingGrossAmount = rest.additionalBookingGrossAmount;
254
+ chargesModel.cancelledBookingGrossAmount = rest.cancelledBookingGrossAmount;
255
+ chargesModel.refundPayable = rest.refundPayable;
256
+ chargesModel.totalRefundedAmount = rest.totalRefundedAmount;
257
+ chargesModel.totalCancellationCharges = rest.totalCancellationCharges;
258
+ chargesModel.netTotal = rest.netTotal;
259
+ chargesModel.amountPayable = rest.amountPayable;
260
+ // Object.assign(chargesModel, rest);
231
261
  return chargesModel;
232
262
  };
233
263
  // static assignByInterface(
@@ -1,5 +1,5 @@
1
1
  import { BookingDetailsStatus } from "../../enums/booking-details-status.enum";
2
- import { IBookingDetailsModel } from "../../interface/model/booking-details-model.interface";
2
+ import { IBookingDetailsModel, IEventBookingDetails } from "../../interface/model/booking-details-model.interface";
3
3
  import { IBookingDetailsWithBooking } from "../../types/bookingdetails-with-booking.type";
4
4
  import { IBookingDetailsEntity } from "../../interface/entity/booking-details-entity.interface";
5
5
  import { IBookingsEntity } from "../../interface/entity/bookings-entity.interface";
@@ -35,6 +35,7 @@ export declare class BookingDetailsModel implements IBookingDetailsModel {
35
35
  totalBookingHours: number;
36
36
  type: string | null;
37
37
  constructor(data: IBookingDetailsEntity);
38
+ getEventDetails(): IEventBookingDetails;
38
39
  static getIdAndCreatedBy(bookingDetailsEntities: IBookingDetailsEntity[]): number[][];
39
40
  assignCharges(chargeModel: ChargesModel): void;
40
41
  static toMap(bookingDetailsEntities: IBookingDetailsEntity[], bookingsEntities: IBookingsEntity[]): IBookingDetailsWithBooking;
@@ -13,10 +13,29 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.BookingDetailsModel = void 0;
15
15
  var booking_entity_model_1 = require("./booking-entity-model");
16
+ var weekday_time_slot_model_1 = require("../weekday-time-slot-model");
16
17
  var BookingDetailsModel = /** @class */ (function () {
17
18
  function BookingDetailsModel(data) {
18
19
  Object.assign(this, data);
19
20
  }
21
+ BookingDetailsModel.prototype.getEventDetails = function () {
22
+ var _a;
23
+ if (((_a = this.type) === null || _a === void 0 ? void 0 : _a.split("#")[0]) === "event") {
24
+ var startDateCode = Number(this.type.split("#")[1].split(",")[0]);
25
+ var endDateCode = Number(this.type.split("#")[1].split(",")[1]);
26
+ var pitchIds = this.type.split("#")[3].split(",").map(Number);
27
+ var weekdaySlots = this.type.split("#")[2].split(",").map(function (weekdayTimeSlotCode) { return new weekday_time_slot_model_1.WeekdayTimeSlot(weekdayTimeSlotCode); });
28
+ return {
29
+ startDateCode: startDateCode,
30
+ endDateCode: endDateCode,
31
+ weekdaySlots: weekdaySlots,
32
+ pitchIds: pitchIds,
33
+ };
34
+ }
35
+ else {
36
+ throw new Error("Booking is not an event");
37
+ }
38
+ };
20
39
  BookingDetailsModel.getIdAndCreatedBy = function (bookingDetailsEntities) {
21
40
  var bookingDetailsIds = [];
22
41
  var userIds = [];
@@ -14,6 +14,7 @@ export declare class BookingEntityModel implements IBookingsEntityModel {
14
14
  getBookingTimeInMinutes(): number;
15
15
  isTimeExtended(newBookingEntities: IBookingsEntity[]): boolean;
16
16
  getBookingCode(): BookingCode;
17
+ isModificationAllowed(): boolean;
17
18
  static toMap(bookingEntities: IBookingsEntity[]): {
18
19
  [key: string]: string;
19
20
  };
@@ -27,6 +27,9 @@ var BookingEntityModel = /** @class */ (function () {
27
27
  BookingEntityModel.prototype.getBookingCode = function () {
28
28
  return new booking_code_model_1.BookingCode(this.code, this.cost);
29
29
  };
30
+ BookingEntityModel.prototype.isModificationAllowed = function () {
31
+ return this.getBookingCode().isModificationAllowed();
32
+ };
30
33
  BookingEntityModel.toMap = function (bookingEntities) {
31
34
  var response = {};
32
35
  bookingEntities.forEach(function (bookingEntity) {
@@ -4,16 +4,16 @@ import { IUserModel } from "../../interface/model/user-model.interface";
4
4
  import { ITurfEntity } from "../../interface/entity/turf-entity.interface";
5
5
  export declare class UserModel implements IUserModel {
6
6
  id: number;
7
- firstname: string;
7
+ name: string;
8
8
  phone: string;
9
9
  password: string;
10
10
  email: string;
11
11
  status: UserStatus;
12
- is_email_verified: boolean;
13
- is_mobile_verified: boolean;
14
- is_account_verified: boolean;
15
- require_new_password: boolean;
16
- organization_id: number;
12
+ isEmailVerified: boolean;
13
+ isMobileVerified: boolean;
14
+ isAccountVerified: boolean;
15
+ requireNewPassword: boolean;
16
+ organizationId: number;
17
17
  type: UserType;
18
18
  createdOn: Date;
19
19
  updatedOn: Date;
@@ -12,6 +12,7 @@ export declare class TimeSlot {
12
12
  getHalfHourTimeCodes(): string[];
13
13
  getHalfHourTimeRangeCodes(): string[];
14
14
  getTotalMinutes(): number;
15
+ isInclusive(timeSlot: TimeSlot): boolean;
15
16
  static convertToCode(minute: number): string;
16
17
  static _getMinutes(timeCode: string): number;
17
18
  static getHalfHourTimeCodes(): string[];
@@ -64,6 +64,9 @@ var TimeSlot = /** @class */ (function () {
64
64
  TimeSlot.prototype.getTotalMinutes = function () {
65
65
  return this.getEndMinutes() - this.getStartMinutes();
66
66
  };
67
+ TimeSlot.prototype.isInclusive = function (timeSlot) {
68
+ return this.fromTime <= timeSlot.fromTime && timeSlot.toTime <= this.toTime;
69
+ };
67
70
  // static padStart(timeCode: string, length: number, padString: string): string {
68
71
  // return timeCode.padStart(length, padString);
69
72
  // }
@@ -1,8 +1,9 @@
1
- import { IGetAvailabilityByTurf } from "../@type";
1
+ import { IGetAvailabilityByTurf, IGetAvailabilityByTurfRequest } from "../@type";
2
2
  interface ITurfAvailability {
3
3
  data: IGetAvailabilityByTurf;
4
4
  dateCodes: string[];
5
5
  timeSlotCodesDateWise: Record<string, string[]>;
6
+ apiRequestModel?: IGetAvailabilityByTurfRequest;
6
7
  getTotalAvailablePrice(): number;
7
8
  getTotalNonAvailablePrice(): number;
8
9
  getTotalAvailableHours(): number;
@@ -26,7 +27,8 @@ export declare class TurfAvailability implements ITurfAvailability {
26
27
  toTimeCode: string;
27
28
  pitchCodes: string[];
28
29
  weekDays: number[];
29
- constructor(data: IGetAvailabilityByTurf);
30
+ apiRequestModel?: IGetAvailabilityByTurfRequest;
31
+ constructor(data: IGetAvailabilityByTurf, apiRequestModel?: IGetAvailabilityByTurfRequest | null);
30
32
  getTotalAvailablePrice(): number;
31
33
  getTotalNonAvailablePrice(): number;
32
34
  getTotalAvailableHours(): number;
@@ -39,10 +41,23 @@ export declare class TurfAvailability implements ITurfAvailability {
39
41
  weekdays: number[];
40
42
  }[];
41
43
  getPitchIds(): number[];
42
- static fromJson(json: IGetAvailabilityByTurf): TurfAvailability;
44
+ static fromJson(json: IGetAvailabilityByTurf, apiRequestModel?: IGetAvailabilityByTurfRequest | null): TurfAvailability;
43
45
  static toJson(turfAvailability: TurfAvailability): IGetAvailabilityByTurf;
44
46
  getTotalTime(): number;
45
47
  getCode(): string;
48
+ getEventCode(): string;
49
+ static parseEventCode(eventCode: string): {
50
+ fromDateCode: string;
51
+ toDateCode: string;
52
+ data: {
53
+ fromDateCode: string;
54
+ toDateCode: string;
55
+ fromTimeCode: string;
56
+ toTimeCode: string;
57
+ weekDay: number;
58
+ }[];
59
+ pitchIds: string[];
60
+ };
46
61
  parse(): void;
47
62
  static parse(eventCode: string): {
48
63
  pitchCodes: string[];
@@ -4,9 +4,13 @@ exports.TurfAvailability = void 0;
4
4
  var _utils_1 = require("../@utils");
5
5
  var booking_code_model_1 = require("./booking-code-model");
6
6
  var TurfAvailability = /** @class */ (function () {
7
- function TurfAvailability(data) {
7
+ function TurfAvailability(data, apiRequestModel) {
8
8
  var _this = this;
9
+ if (apiRequestModel === void 0) { apiRequestModel = null; }
9
10
  this.data = data;
11
+ if (apiRequestModel) {
12
+ this.apiRequestModel = apiRequestModel;
13
+ }
10
14
  this.dateCodes = Object.keys(data).sort();
11
15
  this.timeSlotCodesDateWise = {};
12
16
  Object.entries(data).forEach(function (_a) {
@@ -116,7 +120,8 @@ var TurfAvailability = /** @class */ (function () {
116
120
  var pitchIdList = Array.from(pitchIds).sort(function (a, b) { return a - b; });
117
121
  return pitchIdList;
118
122
  };
119
- TurfAvailability.fromJson = function (json) {
123
+ TurfAvailability.fromJson = function (json, apiRequestModel) {
124
+ if (apiRequestModel === void 0) { apiRequestModel = null; }
120
125
  var data = {};
121
126
  Object.entries(json).forEach(function (_a) {
122
127
  var dateCode = _a[0], value = _a[1];
@@ -141,7 +146,11 @@ var TurfAvailability = /** @class */ (function () {
141
146
  });
142
147
  data[dateCode] = dateData;
143
148
  });
144
- return new TurfAvailability(data);
149
+ var turfAvailability = new TurfAvailability(data);
150
+ if (apiRequestModel) {
151
+ turfAvailability.apiRequestModel = apiRequestModel;
152
+ }
153
+ return turfAvailability;
145
154
  };
146
155
  TurfAvailability.toJson = function (turfAvailability) {
147
156
  var data = {};
@@ -178,6 +187,54 @@ var TurfAvailability = /** @class */ (function () {
178
187
  return "";
179
188
  return "event#".concat(this.dateCodes[0]).concat(this.dateCodes[this.dateCodes.length - 1], "#").concat(this.timeSlotCodesDateWise[this.dateCodes[0]][0].slice(0, 4)).concat(this.timeSlotCodesDateWise[this.dateCodes[0]][this.timeSlotCodesDateWise[this.dateCodes[0]].length - 1].slice(4, 8), "#").concat(this.getPitchIds(), "#").concat(this.weekDays);
180
189
  };
190
+ TurfAvailability.prototype.getEventCode = function () {
191
+ if (this.apiRequestModel) {
192
+ return "event#".concat(this.apiRequestModel.dateRange, "#").concat(this.apiRequestModel.weekdayTimeSlots.join(","), "#").concat(this.apiRequestModel.pitch);
193
+ }
194
+ return "";
195
+ };
196
+ TurfAvailability.parseEventCode = function (eventCode) {
197
+ var eventCodes = eventCode.split("#");
198
+ var dateCodeRange = eventCodes[1];
199
+ var weekdayTimeSlots = eventCodes[2].split(",");
200
+ var timeSlotsByWeekday = {};
201
+ for (var _i = 0, weekdayTimeSlots_1 = weekdayTimeSlots; _i < weekdayTimeSlots_1.length; _i++) {
202
+ var weekdayTimeSlot = weekdayTimeSlots_1[_i];
203
+ var weekday = parseInt(weekdayTimeSlot.slice(0, 1));
204
+ if (!timeSlotsByWeekday[weekday]) {
205
+ timeSlotsByWeekday[weekday] = [];
206
+ }
207
+ timeSlotsByWeekday[weekday].push(weekdayTimeSlot.slice(1));
208
+ }
209
+ var weekdays = Array.from(new Set(weekdayTimeSlots.map(function (timeSlot) { return parseInt(timeSlot.slice(0, 1)); })));
210
+ var dateCodes = [];
211
+ for (var _a = 0, weekdays_1 = weekdays; _a < weekdays_1.length; _a++) {
212
+ var weekday = weekdays_1[_a];
213
+ dateCodes.push.apply(dateCodes, booking_code_model_1.BookingCode.getDateCodesByWeek(Number(dateCodeRange.slice(0, 6)), Number(dateCodeRange.slice(7, 13)), weekday));
214
+ }
215
+ var data = [];
216
+ dateCodes.sort();
217
+ for (var _b = 0, dateCodes_1 = dateCodes; _b < dateCodes_1.length; _b++) {
218
+ var dateCode = dateCodes_1[_b];
219
+ var dateCodeWeekday = booking_code_model_1.BookingCode.getWeekday(Number(dateCode));
220
+ for (var _c = 0, _d = timeSlotsByWeekday[dateCodeWeekday] || []; _c < _d.length; _c++) {
221
+ var timeslot = _d[_c];
222
+ data.push({
223
+ fromDateCode: dateCode,
224
+ toDateCode: dateCode,
225
+ fromTimeCode: timeslot.slice(0, 4),
226
+ toTimeCode: timeslot.slice(4, 8),
227
+ weekDay: dateCodeWeekday,
228
+ });
229
+ }
230
+ }
231
+ return {
232
+ fromDateCode: dateCodes[0],
233
+ toDateCode: dateCodes[dateCodes.length - 1],
234
+ data: data,
235
+ pitchIds: eventCodes[3].split(","),
236
+ };
237
+ };
181
238
  TurfAvailability.prototype.parse = function () {
182
239
  if (!Object.keys(this.data).length)
183
240
  return;
@@ -0,0 +1,12 @@
1
+ import { TimeSlot } from "./time-slot-model";
2
+ export declare class WeekdayTimeSlot {
3
+ code: string;
4
+ weekday: number;
5
+ timeSlot: TimeSlot;
6
+ constructor(code: string);
7
+ parse(): void;
8
+ getWeekday(): number;
9
+ getFromTimeCode(): string;
10
+ getToTimeCode(): string;
11
+ getTimeSlot(): TimeSlot;
12
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WeekdayTimeSlot = void 0;
4
+ var time_slot_model_1 = require("./time-slot-model");
5
+ var WeekdayTimeSlot = /** @class */ (function () {
6
+ function WeekdayTimeSlot(code) {
7
+ if (code.length !== 9)
8
+ throw new Error("Invalid weekday time slot code: ".concat(code, ". Expected length: 9."));
9
+ this.code = code;
10
+ this.parse();
11
+ }
12
+ WeekdayTimeSlot.prototype.parse = function () {
13
+ this.weekday = parseInt(this.code.slice(0, 1));
14
+ this.timeSlot = new time_slot_model_1.TimeSlot(this.code.slice(1, 5), this.code.slice(5, 9));
15
+ };
16
+ WeekdayTimeSlot.prototype.getWeekday = function () {
17
+ return this.weekday;
18
+ };
19
+ WeekdayTimeSlot.prototype.getFromTimeCode = function () {
20
+ return this.timeSlot.fromTime;
21
+ };
22
+ WeekdayTimeSlot.prototype.getToTimeCode = function () {
23
+ return this.timeSlot.toTime;
24
+ };
25
+ WeekdayTimeSlot.prototype.getTimeSlot = function () {
26
+ return this.timeSlot;
27
+ };
28
+ return WeekdayTimeSlot;
29
+ }());
30
+ exports.WeekdayTimeSlot = WeekdayTimeSlot;
@@ -3,3 +3,6 @@ export declare const DEFAULT_PASSWORD = "turf@#123";
3
3
  export declare const DELETED_SLOT_SEPARATOR = "d_";
4
4
  export declare const START_OF_DAY_TIME_CODE = "0000";
5
5
  export declare const END_OF_DAY_TIME_CODE = "2400";
6
+ export declare const DEFAULT_BOOKING_DELAY_IN_MINUTES = 60;
7
+ export declare const DEFAULT_BOOKING_MODIFICATION_DELAY_IN_MINUTES = 120;
8
+ export declare const DEFAULT_BOOKING_DELETION_DELAY_IN_MINUTES: number;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.END_OF_DAY_TIME_CODE = exports.START_OF_DAY_TIME_CODE = exports.DELETED_SLOT_SEPARATOR = exports.DEFAULT_PASSWORD = exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
3
+ exports.DEFAULT_BOOKING_DELETION_DELAY_IN_MINUTES = exports.DEFAULT_BOOKING_MODIFICATION_DELAY_IN_MINUTES = exports.DEFAULT_BOOKING_DELAY_IN_MINUTES = exports.END_OF_DAY_TIME_CODE = exports.START_OF_DAY_TIME_CODE = exports.DELETED_SLOT_SEPARATOR = exports.DEFAULT_PASSWORD = exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
4
4
  exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
5
5
  exports.DEFAULT_PASSWORD = "turf@#123";
6
6
  exports.DELETED_SLOT_SEPARATOR = "d_";
7
7
  exports.START_OF_DAY_TIME_CODE = "0000";
8
8
  exports.END_OF_DAY_TIME_CODE = "2400";
9
+ exports.DEFAULT_BOOKING_DELAY_IN_MINUTES = 60;
10
+ exports.DEFAULT_BOOKING_MODIFICATION_DELAY_IN_MINUTES = 120;
11
+ exports.DEFAULT_BOOKING_DELETION_DELAY_IN_MINUTES = 7 * 24 * 60;
@@ -5,7 +5,9 @@ export declare class DateUtilService {
5
5
  getNDaysCode(n: number): string;
6
6
  getDateCode(date: Date): string;
7
7
  addNDaysToDate(date: Date, n: number): Date;
8
- convertStringToDate(dateString: string, format: string): Date;
8
+ addMinutesTo(date: Date, minutes: number): Date;
9
+ convertStringToDate(dateString: string, format: string, offset?: number): Date;
10
+ getIndianDate(date?: Date): Date;
9
11
  isInPast(date: Date): boolean;
10
12
  getDateFromDatabaseDate: (date: string) => Date;
11
13
  noOfDaysBetweenDates: (date1: Date, date2: Date) => number;
@@ -52,5 +54,10 @@ export declare class DateUtilService {
52
54
  */
53
55
  getBookingCodeByWeekDaysAndDateRange(startDateCode: string, endDateCode: string, weekdays: number[]): string[];
54
56
  formatDate(date: Date, formatString: string): string;
57
+ convertDateToTimezone(date: Date, timeZone: Timezone): Date;
58
+ convertDateToUTC(now: Date): Date;
59
+ }
60
+ export declare enum Timezone {
61
+ IST = "Asia/Kolkata"
55
62
  }
56
63
  export declare const dateUtilService: DateUtilService;