turf-common 1.2.1-beta.8 → 1.3.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 (49) hide show
  1. package/build/@enum.d.ts +2 -0
  2. package/build/@enum.js +2 -0
  3. package/build/@model.d.ts +1 -0
  4. package/build/@model.js +1 -0
  5. package/build/@type.d.ts +2 -0
  6. package/build/@type.js +2 -0
  7. package/build/@utils.d.ts +1 -0
  8. package/build/@utils.js +1 -0
  9. package/build/enums/availability-view.enum.d.ts +4 -0
  10. package/build/enums/availability-view.enum.js +8 -0
  11. package/build/enums/booking-history-operation-type.enum.d.ts +4 -2
  12. package/build/enums/booking-history-operation-type.enum.js +4 -2
  13. package/build/enums/environment.enum.d.ts +5 -0
  14. package/build/enums/environment.enum.js +9 -0
  15. package/build/enums/valid-coupon-type.enum.d.ts +3 -1
  16. package/build/enums/valid-coupon-type.enum.js +2 -0
  17. package/build/interface/api/create-recurring-slot-booking.interface.d.ts +4 -1
  18. package/build/interface/api/get-availability-by-turf.interface.d.ts +29 -0
  19. package/build/interface/api/get-availability-by-turf.interface.js +2 -0
  20. package/build/interface/api/get-tournament.interface.d.ts +4 -0
  21. package/build/interface/api/get-tournament.interface.js +2 -0
  22. package/build/interface/api/index.d.ts +2 -0
  23. package/build/interface/api/index.js +2 -0
  24. package/build/interface/api/list-of-coupons.interface.d.ts +6 -0
  25. package/build/interface/convert-to-midnight-time.interface.d.ts +5 -0
  26. package/build/interface/convert-to-midnight-time.interface.js +2 -0
  27. package/build/interface/entity/booking-details-entity.interface.d.ts +2 -0
  28. package/build/interface/entity/booking-history-entity.interface.d.ts +4 -0
  29. package/build/interface/get-booking-by-id.interface.d.ts +2 -3
  30. package/build/interface/model/charge-model.interface.d.ts +1 -0
  31. package/build/interface/ng-date-structure.interface.d.ts +5 -0
  32. package/build/interface/ng-date-structure.interface.js +2 -0
  33. package/build/models/booking-code-model.d.ts +35 -1
  34. package/build/models/booking-code-model.js +91 -6
  35. package/build/models/charge-model.d.ts +3 -2
  36. package/build/models/charge-model.js +48 -9
  37. package/build/models/entity/booking-details-model.d.ts +2 -0
  38. package/build/models/entity/subscription-model.js +3 -3
  39. package/build/models/turf-availability-model.d.ts +57 -0
  40. package/build/models/turf-availability-model.js +239 -0
  41. package/build/utils/constant.d.ts +2 -0
  42. package/build/utils/constant.js +3 -1
  43. package/build/utils/date-util.d.ts +40 -0
  44. package/build/utils/date-util.js +89 -1
  45. package/build/utils/string-utils.d.ts +12 -0
  46. package/build/utils/string-utils.js +53 -0
  47. package/package.json +1 -1
  48. package/build/utils/format-string-with-hyphens.d.ts +0 -1
  49. package/build/utils/format-string-with-hyphens.js +0 -7
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChargesModel = void 0;
4
4
  var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
5
5
  var modification_discount_policy_enum_1 = require("../enums/modification-discount-policy.enum");
6
+ var _utils_1 = require("../@utils");
6
7
  var ChargesModel = /** @class */ (function () {
7
- function ChargesModel(initialGrossAmount, paidAmount, couponCode, discountPolicy) {
8
+ function ChargesModel(initialGrossAmount, paidAmount, couponCode, totalBookingHours, discountPolicy) {
8
9
  this.initialBookingGrossAmount = initialGrossAmount;
9
10
  this.amountPaid = paidAmount;
10
11
  this.couponCode = couponCode;
@@ -13,6 +14,7 @@ var ChargesModel = /** @class */ (function () {
13
14
  this.totalCancellationCharges = 0;
14
15
  this.refundPayable = 0;
15
16
  this.totalRefundedAmount = 0;
17
+ this.totalBookingHours = totalBookingHours;
16
18
  this.netTotal = this.getNetAmount();
17
19
  this.amountPayable = this.getPayableRefundAmount();
18
20
  this.discountPolicy = discountPolicy;
@@ -33,7 +35,7 @@ var ChargesModel = /** @class */ (function () {
33
35
  this.cancelledBookingGrossAmount > 0) {
34
36
  this.couponCode = "";
35
37
  }
36
- return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount());
38
+ return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount(), false, this.totalBookingHours);
37
39
  };
38
40
  ChargesModel.prototype.getPayableRefundAmount = function () {
39
41
  return (this.getNetAmount() +
@@ -46,11 +48,19 @@ var ChargesModel = /** @class */ (function () {
46
48
  // this.totalRefundAmount = this.totalRefundAmount - refundAmount;
47
49
  // this.refundedAmount += refundAmount;
48
50
  // }
49
- ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply) {
51
+ ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply, totalBookingHours) {
50
52
  if (validationApply === void 0) { validationApply = false; }
51
53
  var discountAmount = 0;
52
54
  if (couponCode) {
53
- if (couponCode.slice(-1) === "P") {
55
+ var code = _utils_1.stringUtil.getCouponDetails(couponCode).code;
56
+ var value = _utils_1.stringUtil.getCouponDetails(couponCode).value;
57
+ if (validationApply && !code && !value) {
58
+ throw new app_badrequest_exception_1.AppBadRequestException({
59
+ key: "couponCode",
60
+ message: ["Coupon with code ".concat(couponCode, " is wrong ")],
61
+ });
62
+ }
63
+ if (code === "P" || code === "PHP") {
54
64
  var percentDiscount = parseFloat(couponCode);
55
65
  if (validationApply && percentDiscount > 90) {
56
66
  throw new app_badrequest_exception_1.AppBadRequestException({
@@ -60,9 +70,20 @@ var ChargesModel = /** @class */ (function () {
60
70
  }
61
71
  discountAmount = totalCost * (percentDiscount / 100);
62
72
  }
63
- else if (couponCode.slice(-1) === "U") {
73
+ else if (code === "U") {
64
74
  discountAmount = parseFloat(couponCode);
65
75
  }
76
+ else if (code === "PHU") {
77
+ if (totalBookingHours === undefined) {
78
+ throw new app_badrequest_exception_1.AppBadRequestException({
79
+ key: "totalBookingHours",
80
+ message: [
81
+ "Total Booking Hours is mandatory to calculate per hour unit",
82
+ ],
83
+ });
84
+ }
85
+ discountAmount = parseFloat(couponCode) * totalBookingHours;
86
+ }
66
87
  }
67
88
  return Math.round(discountAmount);
68
89
  };
@@ -81,13 +102,17 @@ var ChargesModel = /** @class */ (function () {
81
102
  };
82
103
  ChargesModel.prototype.modify = function (bookingModification) {
83
104
  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);
84
109
  if (!newBookingCode) {
85
110
  return this.modifyDelete(oldBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
86
111
  }
87
112
  if (!newBookingCode)
88
113
  return null;
89
- var oldTimeSlotMinutes = oldBookingCode.getTimeslot().getTotalMinutes();
90
- var newTimeSlotMinutes = newBookingCode.getTimeslot().getTotalMinutes();
114
+ var oldTimeSlotMinutes = oldBookingCode.getTotalTime();
115
+ var newTimeSlotMinutes = newBookingCode.getTotalTime();
91
116
  if (oldTimeSlotMinutes === newTimeSlotMinutes) {
92
117
  return this.modifyMove(oldBookingCode, newBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
93
118
  }
@@ -100,7 +125,11 @@ var ChargesModel = /** @class */ (function () {
100
125
  return null;
101
126
  };
102
127
  ChargesModel.prototype.modifyExtend = function (oldBookingCode, newBookingCode) {
128
+ var newTotalBookingHours = this.totalBookingHours -
129
+ oldBookingCode.getTotalTime("hr") +
130
+ (newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
103
131
  var newChargeModel = this.clone();
132
+ newChargeModel.totalBookingHours = newTotalBookingHours;
104
133
  newChargeModel.additionalBookingGrossAmount +=
105
134
  newBookingCode.getCost() - oldBookingCode.getCost();
106
135
  newChargeModel.netTotal = newChargeModel.getNetAmount();
@@ -116,7 +145,11 @@ var ChargesModel = /** @class */ (function () {
116
145
  return newChargeModel;
117
146
  };
118
147
  ChargesModel.prototype.modifyReduce = function (oldBookingCode, newBookingCode, cancellationUnit) {
148
+ var newTotalBookingHours = this.totalBookingHours -
149
+ oldBookingCode.getTotalTime("hr") +
150
+ (newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
119
151
  var newChargeModel = this.clone();
152
+ newChargeModel.totalBookingHours = newTotalBookingHours;
120
153
  newChargeModel.couponCode = "";
121
154
  var costDifference = oldBookingCode.getCost() - newBookingCode.getCost();
122
155
  // console.log(`costDifference ${costDifference}`);
@@ -138,7 +171,11 @@ var ChargesModel = /** @class */ (function () {
138
171
  return newChargeModel;
139
172
  };
140
173
  ChargesModel.prototype.modifyMove = function (oldBookingCode, newBookingCode, cancellationUnit) {
174
+ var newTotalBookingHours = this.totalBookingHours -
175
+ oldBookingCode.getTotalTime("hr") +
176
+ (newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
141
177
  var newChargeModel = this.clone();
178
+ newChargeModel.totalBookingHours = newTotalBookingHours;
142
179
  var costDifference = newBookingCode.getCost() - oldBookingCode.getCost();
143
180
  if (costDifference === 0) {
144
181
  return newChargeModel;
@@ -163,12 +200,14 @@ var ChargesModel = /** @class */ (function () {
163
200
  return newChargeModel;
164
201
  };
165
202
  ChargesModel.prototype.clone = function () {
166
- var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.discountPolicy);
203
+ var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.totalBookingHours, this.discountPolicy);
167
204
  Object.assign(that, this);
168
205
  return that;
169
206
  };
170
207
  ChargesModel.prototype.modifyDelete = function (bookingCode, cancellationUnit) {
208
+ var newTotalBookingHours = this.totalBookingHours - bookingCode.getTotalTime("hr");
171
209
  var newChargeModel = this.clone();
210
+ newChargeModel.totalBookingHours = newTotalBookingHours;
172
211
  newChargeModel.couponCode = "";
173
212
  var costDifference = bookingCode.getCost();
174
213
  newChargeModel.cancelledBookingGrossAmount += costDifference;
@@ -187,7 +226,7 @@ var ChargesModel = /** @class */ (function () {
187
226
  };
188
227
  ChargesModel.getInstance = function (chargeData, discountPolicy) {
189
228
  if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
190
- var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, discountPolicy);
229
+ var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
191
230
  Object.assign(chargesModel, chargeData);
192
231
  return chargesModel;
193
232
  };
@@ -32,6 +32,8 @@ export declare class BookingDetailsModel implements IBookingDetailsModel {
32
32
  updatedOn: Date;
33
33
  createdBy: number;
34
34
  updatedBy: number;
35
+ totalBookingHours: number;
36
+ type: string | null;
35
37
  constructor(data: IBookingDetailsEntity);
36
38
  static getIdAndCreatedBy(bookingDetailsEntities: IBookingDetailsEntity[]): number[][];
37
39
  assignCharges(chargeModel: ChargesModel): void;
@@ -45,10 +45,10 @@ var SubscriptionModel = /** @class */ (function () {
45
45
  return new SubscriptionModel(demo);
46
46
  };
47
47
  SubscriptionModel.prototype.getFromDate = function () {
48
- return this.from;
48
+ return date_util_1.dateUtilService.convertStringToDate(this.fromDateCode, "yyMMdd");
49
49
  };
50
50
  SubscriptionModel.prototype.getToDate = function () {
51
- return this.to;
51
+ return date_util_1.dateUtilService.convertStringToDate(this.toDateCode, "yyMMdd");
52
52
  };
53
53
  SubscriptionModel.prototype.isRenewalDue = function () {
54
54
  // Check if difference 'to' date and today's date is less than 7 days
@@ -92,7 +92,7 @@ var SubscriptionModel = /** @class */ (function () {
92
92
  // dateService.convertStringToDate(this.from, "yyyy-MM-dd");
93
93
  // const subscribedPitchCount: number = this.noOfPitches;
94
94
  var renewalSubscriptionModel = new subscribed_pricing_plan_model_1.SubscribedPricingPlanModel(currentPricingPlanModel, totalPitchCount, billingCycle);
95
- var toDate = this.to;
95
+ var toDate = this.getToDate();
96
96
  var _a = renewalSubscriptionModel.getNextBillingCycleDateRange(toDate), startDate = _a[0], endDate = _a[1];
97
97
  // const [startDateCode, endDateCode]: [string, string] = [
98
98
  // dateService.getDateCode(startDate),
@@ -0,0 +1,57 @@
1
+ import { IGetAvailabilityByTurf } from "../@type";
2
+ interface ITurfAvailability {
3
+ data: IGetAvailabilityByTurf;
4
+ dateCodes: string[];
5
+ timeSlotCodesDateWise: Record<string, string[]>;
6
+ getTotalAvailablePrice(): number;
7
+ getTotalNonAvailablePrice(): number;
8
+ getTotalAvailableHours(): number;
9
+ getTotalNonAvailableHours(): number;
10
+ getSlots(): {
11
+ fromDate: number;
12
+ toDate: number;
13
+ from: string;
14
+ to: string;
15
+ weekdays: number[];
16
+ }[];
17
+ getPitchIds(): number[];
18
+ }
19
+ export declare class TurfAvailability implements ITurfAvailability {
20
+ data: IGetAvailabilityByTurf;
21
+ dateCodes: string[];
22
+ timeSlotCodesDateWise: Record<string, string[]>;
23
+ startDateCode: string;
24
+ endDateCode: string;
25
+ fromTimeCode: string;
26
+ toTimeCode: string;
27
+ pitchCodes: string[];
28
+ weekDays: number[];
29
+ constructor(data: IGetAvailabilityByTurf);
30
+ getTotalAvailablePrice(): number;
31
+ getTotalNonAvailablePrice(): number;
32
+ getTotalAvailableHours(): number;
33
+ getTotalNonAvailableHours(): number;
34
+ getSlots(): {
35
+ fromDate: number;
36
+ toDate: number;
37
+ from: string;
38
+ to: string;
39
+ weekdays: number[];
40
+ }[];
41
+ getPitchIds(): number[];
42
+ static fromJson(json: IGetAvailabilityByTurf): TurfAvailability;
43
+ static toJson(turfAvailability: TurfAvailability): IGetAvailabilityByTurf;
44
+ getTotalTime(): number;
45
+ getCode(): string;
46
+ parse(): void;
47
+ static parse(eventCode: string): {
48
+ pitchCodes: string[];
49
+ startDateCode: string;
50
+ endDateCode: string;
51
+ fromTimeCode: string;
52
+ toTimeCode: string;
53
+ bookingDateCodes: string[];
54
+ weekDays: number[];
55
+ };
56
+ }
57
+ export {};
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TurfAvailability = void 0;
4
+ var _utils_1 = require("../@utils");
5
+ var booking_code_model_1 = require("./booking-code-model");
6
+ var TurfAvailability = /** @class */ (function () {
7
+ function TurfAvailability(data) {
8
+ var _this = this;
9
+ this.data = data;
10
+ this.dateCodes = Object.keys(data).sort();
11
+ this.timeSlotCodesDateWise = {};
12
+ Object.entries(data).forEach(function (_a) {
13
+ var key = _a[0], value = _a[1];
14
+ _this.timeSlotCodesDateWise[key] = Object.keys(value).sort();
15
+ });
16
+ if (Object.keys(data))
17
+ this.parse();
18
+ }
19
+ TurfAvailability.prototype.getTotalAvailablePrice = function () {
20
+ var totalCost = 0;
21
+ Object.entries(this.data).forEach(function (_a) {
22
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
23
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
24
+ var timeCode = _a[0], detailsPitchWise = _a[1];
25
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
26
+ var pitchCode = _a[0], details = _a[1];
27
+ if (!details.bookingId) {
28
+ totalCost += details.price;
29
+ }
30
+ });
31
+ });
32
+ });
33
+ return totalCost;
34
+ };
35
+ TurfAvailability.prototype.getTotalNonAvailablePrice = function () {
36
+ var totalCost = 0;
37
+ Object.entries(this.data).forEach(function (_a) {
38
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
39
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
40
+ var timeCode = _a[0], detailsPitchWise = _a[1];
41
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
42
+ var pitchCode = _a[0], details = _a[1];
43
+ if (details.bookingId !== undefined) {
44
+ totalCost += details.price;
45
+ }
46
+ });
47
+ });
48
+ });
49
+ return totalCost;
50
+ };
51
+ TurfAvailability.prototype.getTotalAvailableHours = function () {
52
+ var totalMinutes = 0;
53
+ Object.entries(this.data).forEach(function (_a) {
54
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
55
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
56
+ var timeCode = _a[0], detailsPitchWise = _a[1];
57
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
58
+ var pitchCode = _a[0], details = _a[1];
59
+ pitchCode = pitchCode.padStart(2, "0");
60
+ if (!details.bookingId) {
61
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
62
+ }
63
+ });
64
+ });
65
+ });
66
+ return totalMinutes / 60;
67
+ };
68
+ TurfAvailability.prototype.getTotalNonAvailableHours = function () {
69
+ var totalMinutes = 0;
70
+ Object.entries(this.data).forEach(function (_a) {
71
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
72
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
73
+ var timeCode = _a[0], detailsPitchWise = _a[1];
74
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
75
+ var pitchCode = _a[0], details = _a[1];
76
+ pitchCode = pitchCode.padStart(2, "0");
77
+ if (details.bookingId !== undefined) {
78
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
79
+ }
80
+ });
81
+ });
82
+ });
83
+ return totalMinutes / 60;
84
+ };
85
+ TurfAvailability.prototype.getSlots = function () {
86
+ this.dateCodes.sort(function (a, b) { return a.localeCompare(b); });
87
+ var fromDate = this.dateCodes[0];
88
+ var toDate = this.dateCodes[this.dateCodes.length - 1];
89
+ var fromDateTimeSlots = this.timeSlotCodesDateWise[fromDate];
90
+ var toDateTimeSlots = this.timeSlotCodesDateWise[toDate];
91
+ fromDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
92
+ toDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
93
+ var fromTime = fromDateTimeSlots[0].substring(0, 4);
94
+ var toTime = toDateTimeSlots[toDateTimeSlots.length - 1].substring(4, 8);
95
+ return [
96
+ {
97
+ fromDate: parseInt(fromDate, 10),
98
+ toDate: parseInt(toDate, 10),
99
+ from: fromTime,
100
+ to: toTime,
101
+ weekdays: [1, 2, 3, 4, 5, 6, 7],
102
+ },
103
+ ];
104
+ };
105
+ TurfAvailability.prototype.getPitchIds = function () {
106
+ var pitchIds = new Set();
107
+ var slots = this.getSlots();
108
+ if (this.data[slots[0].fromDate.toString()]) {
109
+ Object.entries(this.data[slots[0].fromDate.toString()]).forEach(function (_a) {
110
+ var timeCode = _a[0], detailsPitchWise = _a[1];
111
+ Object.keys(detailsPitchWise.details).forEach(function (pitchCode) {
112
+ pitchIds.add(parseInt(pitchCode, 10));
113
+ });
114
+ });
115
+ }
116
+ var pitchIdList = Array.from(pitchIds).sort(function (a, b) { return a - b; });
117
+ return pitchIdList;
118
+ };
119
+ TurfAvailability.fromJson = function (json) {
120
+ var data = {};
121
+ Object.entries(json).forEach(function (_a) {
122
+ var dateCode = _a[0], value = _a[1];
123
+ var dateData = {};
124
+ Object.entries(value).forEach(function (_a) {
125
+ var timeCode = _a[0], value = _a[1];
126
+ var timeSlotData = {};
127
+ Object.entries(value.details).forEach(function (_a) {
128
+ var pitchCode = _a[0], value = _a[1];
129
+ timeSlotData[pitchCode] = new TurfAvailabilityDetail({
130
+ price: value.price,
131
+ bookingId: value.bookingId,
132
+ status: value.status,
133
+ priceSlot: value.priceSlot,
134
+ });
135
+ });
136
+ dateData[timeCode] = new TurfAvailabilityBooking({
137
+ available: value.available,
138
+ notavailable: value.notavailable,
139
+ details: timeSlotData,
140
+ });
141
+ });
142
+ data[dateCode] = dateData;
143
+ });
144
+ return new TurfAvailability(data);
145
+ };
146
+ TurfAvailability.toJson = function (turfAvailability) {
147
+ var data = {};
148
+ Object.entries(turfAvailability.data).forEach(function (_a) {
149
+ var dateCode = _a[0], value = _a[1];
150
+ var dateData = {};
151
+ Object.entries(value).forEach(function (_a) {
152
+ var timeCode = _a[0], value = _a[1];
153
+ var timeSlotData = {};
154
+ Object.entries(value.details).forEach(function (_a) {
155
+ var pitchCode = _a[0], value = _a[1];
156
+ timeSlotData[pitchCode] = {
157
+ price: value.price,
158
+ bookingId: value.bookingId,
159
+ status: value.status,
160
+ priceSlot: value.priceSlot,
161
+ };
162
+ });
163
+ dateData[timeCode] = {
164
+ available: value.available,
165
+ notavailable: value.notavailable,
166
+ details: timeSlotData,
167
+ };
168
+ });
169
+ data[dateCode] = dateData;
170
+ });
171
+ return data;
172
+ };
173
+ TurfAvailability.prototype.getTotalTime = function () {
174
+ return this.getTotalAvailableHours() + this.getTotalNonAvailableHours();
175
+ };
176
+ TurfAvailability.prototype.getCode = function () {
177
+ if (!Object.keys(this.data).length)
178
+ return "";
179
+ 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
+ };
181
+ TurfAvailability.prototype.parse = function () {
182
+ if (!Object.keys(this.data).length)
183
+ return;
184
+ var eventCode = this.getCode();
185
+ var eventCodes = eventCode.split("#");
186
+ var dateCodeRange = eventCodes[1];
187
+ var timeCodeRange = eventCodes[2];
188
+ this.pitchCodes = eventCodes[3].split(",").map(function (id) { return id.padStart(2, "0"); });
189
+ this.startDateCode = dateCodeRange.slice(0, 6);
190
+ this.endDateCode = dateCodeRange.slice(6, 12);
191
+ this.fromTimeCode = timeCodeRange.slice(0, 4);
192
+ this.toTimeCode = timeCodeRange.slice(4, 8);
193
+ this.weekDays = Array.from(new Set(this.dateCodes.map(function (dateCode) {
194
+ return booking_code_model_1.BookingCode.getWeekday(Number(dateCode));
195
+ }))).sort();
196
+ };
197
+ TurfAvailability.parse = function (eventCode) {
198
+ var _a;
199
+ var eventCodes = eventCode.split("#");
200
+ var dateCodeRange = eventCodes[1];
201
+ var timeCodeRange = eventCodes[2];
202
+ var weekDays = ((_a = eventCodes[4]) === null || _a === void 0 ? void 0 : _a.split(",").map(Number)) || [-1];
203
+ var startDateCode = dateCodeRange.slice(0, 6);
204
+ var endDateCode = dateCodeRange.slice(6, 12);
205
+ var bookingDateCodes = !weekDays.includes(-1)
206
+ ? _utils_1.dateUtilService.getBookingCodeByWeekDaysAndDateRange(startDateCode, endDateCode, weekDays)
207
+ : [];
208
+ return {
209
+ pitchCodes: eventCodes[3].split(",").map(function (id) { return id.padStart(2, "0"); }),
210
+ startDateCode: startDateCode,
211
+ endDateCode: endDateCode,
212
+ fromTimeCode: timeCodeRange.slice(0, 4),
213
+ toTimeCode: timeCodeRange.slice(4, 8),
214
+ bookingDateCodes: bookingDateCodes,
215
+ weekDays: weekDays,
216
+ };
217
+ };
218
+ return TurfAvailability;
219
+ }());
220
+ exports.TurfAvailability = TurfAvailability;
221
+ var TurfAvailabilityDetail = /** @class */ (function () {
222
+ function TurfAvailabilityDetail(_a) {
223
+ var price = _a.price, bookingId = _a.bookingId, status = _a.status, priceSlot = _a.priceSlot;
224
+ this.price = price;
225
+ this.bookingId = bookingId;
226
+ this.status = status;
227
+ this.priceSlot = priceSlot;
228
+ }
229
+ return TurfAvailabilityDetail;
230
+ }());
231
+ var TurfAvailabilityBooking = /** @class */ (function () {
232
+ function TurfAvailabilityBooking(_a) {
233
+ var available = _a.available, notavailable = _a.notavailable, details = _a.details;
234
+ this.available = available;
235
+ this.notavailable = notavailable;
236
+ this.details = details;
237
+ }
238
+ return TurfAvailabilityBooking;
239
+ }());
@@ -1 +1,3 @@
1
1
  export declare const SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
2
+ export declare const DEFAULT_PASSWORD = "turf@#123";
3
+ export declare const DELETED_SLOT_SEPARATOR = "d_";
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
3
+ exports.DELETED_SLOT_SEPARATOR = exports.DEFAULT_PASSWORD = exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
4
4
  exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
5
+ exports.DEFAULT_PASSWORD = "turf@#123";
6
+ exports.DELETED_SLOT_SEPARATOR = "d_";
@@ -1,3 +1,4 @@
1
+ import { IConvertToMidNightTime, INgbDateStruct } from "../@type";
1
2
  export declare class DateUtilService {
2
3
  constructor();
3
4
  getTodayCode(): string;
@@ -12,5 +13,44 @@ export declare class DateUtilService {
12
13
  formatTimeSlotCode(timeSlot: string, both?: boolean, date?: Date | null): string;
13
14
  formatDateCode(dateCode: string): string;
14
15
  getDateNDaysFromToday(n: number): Date;
16
+ calculateDateDifference(fromDateCode: string, toDateCode: string, unit?: "minute" | "hr"): number;
17
+ /**
18
+ * Handles the special case when the hours and minutes portion of the date code is set to "2400" by adjusting to the next day.
19
+ *
20
+ * @param {string} dateCode - The original date code.
21
+ * @returns {string} The adjusted date code.
22
+ */
23
+ handle2400HourInDateCode(dateTimeCode: string): string;
24
+ /**
25
+ * Adds or subtracts a specified number of months from a given date in YYMM format.
26
+ *
27
+ * @param {string} dateCode - A string representing a date in YYMM format.
28
+ * @param {number} N - An integer representing the number of months to add or subtract.
29
+ * Use a positive value to add months and a negative value to subtract months.
30
+ * @returns {string} A string representing the resulting date in YYMM format.
31
+ */
32
+ addNMonth(dateCode: string, N: number): string;
33
+ /**
34
+ * Gets an array of month codes between two specified dates (inclusive).
35
+ * Each month code is represented as a number in the format "yyMM," where "yy" is the two-digit year and "MM" is the two-digit month.
36
+ *
37
+ * @param {string} startDateCode - The starting date code in "yyMMdd" format.
38
+ * @param {string} endDateCode - The ending date code in "yyMMdd" format.
39
+ * @returns {number[]} An array of month codes representing each month between the start and end dates (inclusive).
40
+ * Each element in the array is a number in the "yyMM" format.
41
+ */
42
+ getMonthRangeByDateCodes(startDateCode: string, endDateCode: string): number[];
43
+ convertToMidnight(time: IConvertToMidNightTime): IConvertToMidNightTime;
44
+ convertMonthsToNumber: (months: INgbDateStruct) => string;
45
+ /**
46
+ * Retrieves booking date codes for a specified date range and weekdays.
47
+ *
48
+ * @param startDateCode - The starting date code for the date range.
49
+ * @param endDateCode - The ending date code for the date range.
50
+ * @param weekdays - An array of numbers representing weekdays (1 for Monday through 7 for Sunday).
51
+ * @returns An array of booking date codes based on the provided date range and weekdays.
52
+ */
53
+ getBookingCodeByWeekDaysAndDateRange(startDateCode: string, endDateCode: string, weekdays: number[]): string[];
54
+ formatDate(date: Date, formatString: string): string;
15
55
  }
16
56
  export declare const dateUtilService: DateUtilService;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dateUtilService = exports.DateUtilService = void 0;
4
4
  var date_fns_1 = require("date-fns");
5
+ var _model_1 = require("../@model");
5
6
  var DateUtilService = /** @class */ (function () {
6
7
  function DateUtilService() {
7
8
  this.getDateFromDatabaseDate = function (date) { return (0, date_fns_1.parseISO)(date); };
@@ -10,6 +11,13 @@ var DateUtilService = /** @class */ (function () {
10
11
  var dayDifference = Math.ceil((date2.getTime() - date1.getTime()) / oneDay);
11
12
  return dayDifference - 1; //minus 1 day
12
13
  };
14
+ this.convertMonthsToNumber = function (months) {
15
+ var year = months.year.toString().slice(2, 4);
16
+ var month = months.month.toString().padStart(2, "0");
17
+ var day = months.day.toString().padStart(2, "0");
18
+ var dates = year.concat(month).concat(day);
19
+ return "".concat(dates);
20
+ };
13
21
  }
14
22
  DateUtilService.prototype.getTodayCode = function () {
15
23
  return (0, date_fns_1.format)(new Date(), "yyMMdd");
@@ -24,7 +32,10 @@ var DateUtilService = /** @class */ (function () {
24
32
  return (0, date_fns_1.add)(date, { days: n });
25
33
  };
26
34
  DateUtilService.prototype.convertStringToDate = function (dateString, format) {
27
- return (0, date_fns_1.parse)(dateString, format, new Date());
35
+ var parsedDate = (0, date_fns_1.parse)(dateString, format, new Date());
36
+ // IST has a fixed offset of UTC+5:30
37
+ var indianDate = new Date(parsedDate.getTime() + 330 * 60 * 1000);
38
+ return indianDate;
28
39
  };
29
40
  DateUtilService.prototype.isInPast = function (date) {
30
41
  return date < new Date();
@@ -63,6 +74,83 @@ var DateUtilService = /** @class */ (function () {
63
74
  futureDate.setDate(today.getDate() + n);
64
75
  return futureDate;
65
76
  };
77
+ DateUtilService.prototype.calculateDateDifference = function (fromDateCode, toDateCode, unit) {
78
+ if (unit === void 0) { unit = "minute"; }
79
+ toDateCode = this.handle2400HourInDateCode(toDateCode);
80
+ var fromDate = (0, date_fns_1.parse)(fromDateCode, "yyMMddHHmm", new Date());
81
+ var toDate = (0, date_fns_1.parse)(toDateCode, "yyMMddHHmm", new Date());
82
+ var minutesDifference = (0, date_fns_1.differenceInMinutes)(toDate, fromDate);
83
+ return unit === "minute"
84
+ ? minutesDifference
85
+ : parseFloat((minutesDifference / 60).toFixed(1));
86
+ };
87
+ /**
88
+ * Handles the special case when the hours and minutes portion of the date code is set to "2400" by adjusting to the next day.
89
+ *
90
+ * @param {string} dateCode - The original date code.
91
+ * @returns {string} The adjusted date code.
92
+ */
93
+ DateUtilService.prototype.handle2400HourInDateCode = function (dateTimeCode) {
94
+ if (dateTimeCode.slice(-4, -2) === "24") {
95
+ dateTimeCode =
96
+ exports.dateUtilService.addNDaysToDateCode(dateTimeCode.slice(0, -4), 1) +
97
+ "00" +
98
+ dateTimeCode.slice(-2);
99
+ }
100
+ return dateTimeCode;
101
+ };
102
+ /**
103
+ * Adds or subtracts a specified number of months from a given date in YYMM format.
104
+ *
105
+ * @param {string} dateCode - A string representing a date in YYMM format.
106
+ * @param {number} N - An integer representing the number of months to add or subtract.
107
+ * Use a positive value to add months and a negative value to subtract months.
108
+ * @returns {string} A string representing the resulting date in YYMM format.
109
+ */
110
+ DateUtilService.prototype.addNMonth = function (dateCode, N) {
111
+ var date = (0, date_fns_1.parse)("20".concat(dateCode), "yyyyMM", new Date());
112
+ var resultDate = N >= 0 ? (0, date_fns_1.addMonths)(date, N) : (0, date_fns_1.subMonths)(date, Math.abs(N));
113
+ return (0, date_fns_1.format)(resultDate, "yyMM");
114
+ };
115
+ /**
116
+ * Gets an array of month codes between two specified dates (inclusive).
117
+ * Each month code is represented as a number in the format "yyMM," where "yy" is the two-digit year and "MM" is the two-digit month.
118
+ *
119
+ * @param {string} startDateCode - The starting date code in "yyMMdd" format.
120
+ * @param {string} endDateCode - The ending date code in "yyMMdd" format.
121
+ * @returns {number[]} An array of month codes representing each month between the start and end dates (inclusive).
122
+ * Each element in the array is a number in the "yyMM" format.
123
+ */
124
+ DateUtilService.prototype.getMonthRangeByDateCodes = function (startDateCode, endDateCode) {
125
+ var startDate = exports.dateUtilService.convertStringToDate(startDateCode, "yyMMdd");
126
+ var endDate = exports.dateUtilService.convertStringToDate(endDateCode, "yyMMdd");
127
+ return _model_1.BookingCode.getMonthCodesRange(startDate, endDate);
128
+ };
129
+ DateUtilService.prototype.convertToMidnight = function (time) {
130
+ if (time.hour === 0 && time.minute === 0)
131
+ return { hour: 24, minute: 0 };
132
+ return time;
133
+ };
134
+ /**
135
+ * Retrieves booking date codes for a specified date range and weekdays.
136
+ *
137
+ * @param startDateCode - The starting date code for the date range.
138
+ * @param endDateCode - The ending date code for the date range.
139
+ * @param weekdays - An array of numbers representing weekdays (1 for Monday through 7 for Sunday).
140
+ * @returns An array of booking date codes based on the provided date range and weekdays.
141
+ */
142
+ DateUtilService.prototype.getBookingCodeByWeekDaysAndDateRange = function (startDateCode, endDateCode, weekdays) {
143
+ var bookingDateCodes = [];
144
+ weekdays.forEach(function (weekDay) {
145
+ var startDateCodeCopy = Number(startDateCode);
146
+ var endDateCodeCopy = Number(endDateCode);
147
+ bookingDateCodes.push.apply(bookingDateCodes, _model_1.BookingCode.getDateCodesByWeek(startDateCodeCopy, endDateCodeCopy, weekDay));
148
+ });
149
+ return bookingDateCodes.map(Number).sort().map(String);
150
+ };
151
+ DateUtilService.prototype.formatDate = function (date, formatString) {
152
+ return (0, date_fns_1.format)(date, formatString);
153
+ };
66
154
  return DateUtilService;
67
155
  }());
68
156
  exports.DateUtilService = DateUtilService;