turf-common 1.2.1-beta.5 → 1.2.1-beta.50

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 (43) 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/@utils.d.ts +1 -0
  6. package/build/@utils.js +1 -0
  7. package/build/enums/availability-view.enum.d.ts +4 -0
  8. package/build/enums/availability-view.enum.js +8 -0
  9. package/build/enums/booking-history-operation-type.enum.d.ts +2 -1
  10. package/build/enums/booking-history-operation-type.enum.js +1 -0
  11. package/build/enums/environment.enum.d.ts +5 -0
  12. package/build/enums/environment.enum.js +9 -0
  13. package/build/enums/valid-coupon-type.enum.d.ts +3 -1
  14. package/build/enums/valid-coupon-type.enum.js +2 -0
  15. package/build/interface/api/create-recurring-slot-booking.interface.d.ts +4 -1
  16. package/build/interface/api/get-availability-by-turf.interface.d.ts +28 -0
  17. package/build/interface/api/get-availability-by-turf.interface.js +2 -0
  18. package/build/interface/api/get-tournament.interface.d.ts +4 -0
  19. package/build/interface/api/get-tournament.interface.js +2 -0
  20. package/build/interface/api/index.d.ts +2 -0
  21. package/build/interface/api/index.js +2 -0
  22. package/build/interface/api/list-of-coupons.interface.d.ts +6 -0
  23. package/build/interface/entity/booking-details-entity.interface.d.ts +2 -0
  24. package/build/interface/get-booking-by-id.interface.d.ts +2 -3
  25. package/build/interface/model/charge-model.interface.d.ts +1 -0
  26. package/build/interface/ui/booking-data.interface.d.ts +1 -1
  27. package/build/models/booking-code-model.d.ts +21 -1
  28. package/build/models/booking-code-model.js +55 -3
  29. package/build/models/charge-model.d.ts +4 -4
  30. package/build/models/charge-model.js +76 -31
  31. package/build/models/entity/booking-details-model.d.ts +2 -0
  32. package/build/models/entity/subscription-model.js +3 -3
  33. package/build/models/turf-availability-model.d.ts +54 -0
  34. package/build/models/turf-availability-model.js +221 -0
  35. package/build/utils/constant.d.ts +1 -0
  36. package/build/utils/constant.js +2 -1
  37. package/build/utils/date-util.d.ts +21 -1
  38. package/build/utils/date-util.js +52 -2
  39. package/build/utils/string-utils.d.ts +12 -0
  40. package/build/utils/string-utils.js +53 -0
  41. package/package.json +1 -1
  42. package/build/utils/format-string-with-hyphens.d.ts +0 -1
  43. package/build/utils/format-string-with-hyphens.js +0 -7
package/build/@enum.d.ts CHANGED
@@ -22,3 +22,5 @@ export * from "./enums/booking-fetch-filter.enum";
22
22
  export * from "./enums/timezone.enum";
23
23
  export * from "./enums/bookings-status.enum";
24
24
  export * from "./enums/organization-type.enum";
25
+ export * from "./enums/environment.enum";
26
+ export * from "./enums/availability-view.enum";
package/build/@enum.js CHANGED
@@ -38,3 +38,5 @@ __exportStar(require("./enums/booking-fetch-filter.enum"), exports);
38
38
  __exportStar(require("./enums/timezone.enum"), exports);
39
39
  __exportStar(require("./enums/bookings-status.enum"), exports);
40
40
  __exportStar(require("./enums/organization-type.enum"), exports);
41
+ __exportStar(require("./enums/environment.enum"), exports);
42
+ __exportStar(require("./enums/availability-view.enum"), exports);
package/build/@model.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./models/pitch-slab-model";
6
6
  export * from "./models/pricing-plan-model";
7
7
  export * from "./models/subscribed-pricing-plan-model";
8
8
  export * from "./models/entity";
9
+ export * from "./models/turf-availability-model";
package/build/@model.js CHANGED
@@ -22,3 +22,4 @@ __exportStar(require("./models/pitch-slab-model"), exports);
22
22
  __exportStar(require("./models/pricing-plan-model"), exports);
23
23
  __exportStar(require("./models/subscribed-pricing-plan-model"), exports);
24
24
  __exportStar(require("./models/entity"), exports);
25
+ __exportStar(require("./models/turf-availability-model"), exports);
package/build/@utils.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from "./interface/api/utils";
2
2
  export * from "./utils/string-utils";
3
3
  export * from "./utils/date-util";
4
4
  export * from "./utils/math-util";
5
+ export * from "./utils/constant";
package/build/@utils.js CHANGED
@@ -18,3 +18,4 @@ __exportStar(require("./interface/api/utils"), exports);
18
18
  __exportStar(require("./utils/string-utils"), exports);
19
19
  __exportStar(require("./utils/date-util"), exports);
20
20
  __exportStar(require("./utils/math-util"), exports);
21
+ __exportStar(require("./utils/constant"), exports);
@@ -0,0 +1,4 @@
1
+ export declare enum AvailabilityView {
2
+ NORMAL = "normal",
3
+ MERGED = "merged"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AvailabilityView = void 0;
4
+ var AvailabilityView;
5
+ (function (AvailabilityView) {
6
+ AvailabilityView["NORMAL"] = "normal";
7
+ AvailabilityView["MERGED"] = "merged";
8
+ })(AvailabilityView || (exports.AvailabilityView = AvailabilityView = {}));
@@ -5,6 +5,7 @@ export declare enum BookingHistoryOperationType {
5
5
  DELETE_INSERT = "delete_insert",
6
6
  DELETE_SLOT = "delete_slot",
7
7
  REFUND = "refund",
8
- PAYMENT = "payment"
8
+ PAYMENT = "payment",
9
+ MERGED = "merged"
9
10
  }
10
11
  export declare const operationTypes: BookingHistoryOperationType[];
@@ -10,6 +10,7 @@ var BookingHistoryOperationType;
10
10
  BookingHistoryOperationType["DELETE_SLOT"] = "delete_slot";
11
11
  BookingHistoryOperationType["REFUND"] = "refund";
12
12
  BookingHistoryOperationType["PAYMENT"] = "payment";
13
+ BookingHistoryOperationType["MERGED"] = "merged";
13
14
  })(BookingHistoryOperationType || (exports.BookingHistoryOperationType = BookingHistoryOperationType = {}));
14
15
  exports.operationTypes = [
15
16
  BookingHistoryOperationType.DELETE,
@@ -0,0 +1,5 @@
1
+ export declare enum Environment {
2
+ DEVELOPMENT = "development",
3
+ PRODUCTION = "production",
4
+ TEST = "test"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Environment = void 0;
4
+ var Environment;
5
+ (function (Environment) {
6
+ Environment["DEVELOPMENT"] = "development";
7
+ Environment["PRODUCTION"] = "production";
8
+ Environment["TEST"] = "test";
9
+ })(Environment || (exports.Environment = Environment = {}));
@@ -1,4 +1,6 @@
1
1
  export declare enum ValidCouponType {
2
2
  PERCENTAGE = "percentage",
3
- UNIT = "unit"
3
+ UNIT = "unit",
4
+ PER_HOUR_UNIT = "per hour unit",
5
+ PER_HOUR_PERCENTAGE = "per hour percentage"
4
6
  }
@@ -5,4 +5,6 @@ var ValidCouponType;
5
5
  (function (ValidCouponType) {
6
6
  ValidCouponType["PERCENTAGE"] = "percentage";
7
7
  ValidCouponType["UNIT"] = "unit";
8
+ ValidCouponType["PER_HOUR_UNIT"] = "per hour unit";
9
+ ValidCouponType["PER_HOUR_PERCENTAGE"] = "per hour percentage";
8
10
  })(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
@@ -1,5 +1,5 @@
1
1
  import { PaymentMode, BookingDetailsStatus } from "../../@enum";
2
- import { IBookingDetailsEntity, IModifyEntity } from "../../@type";
2
+ import { IBookingDetailsEntity, IGetAvailabilityByTurf, IModifyEntity } from "../../@type";
3
3
  export interface ICreateRecurringSlotBookingResponse extends IModifyEntity<IBookingDetailsEntity> {
4
4
  }
5
5
  export interface ICreateRecurringSlotsBookingDetailsRequest {
@@ -16,6 +16,9 @@ export interface ICreateRecurringSlotsBookingDetailsRequest {
16
16
  sport: string;
17
17
  remarks?: string | null;
18
18
  slot: IRecurringSlot[];
19
+ turf_slot?: {
20
+ availability_details: IGetAvailabilityByTurf;
21
+ };
19
22
  }
20
23
  export declare class IRecurringSlot {
21
24
  fromDate: number;
@@ -0,0 +1,28 @@
1
+ import { BookingDetailsStatus } from "../../@enum";
2
+ import { AvailabilityView } from "../../enums/availability-view.enum";
3
+ export interface IGetAvailabilityByTurfRequest {
4
+ dateRange: string;
5
+ timeRange?: string;
6
+ pitch: string;
7
+ view: AvailabilityView;
8
+ }
9
+ export interface IGetAvailabilityByTurf {
10
+ [dateCode: string]: IAvailabilityData;
11
+ }
12
+ export interface ITurfAvailabilityDetails {
13
+ [pitchId: string]: ITurfAvailabilityDetail;
14
+ }
15
+ export interface ITurfAvailabilityDetail {
16
+ price: number;
17
+ bookingId?: number;
18
+ status?: BookingDetailsStatus;
19
+ priceSlot?: string;
20
+ }
21
+ export interface IAvailabilityData {
22
+ [timeSlot: string]: ITurfAvailabilityBooking;
23
+ }
24
+ export interface ITurfAvailabilityBooking {
25
+ available: number[];
26
+ notavailable: number[];
27
+ details: ITurfAvailabilityDetails;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { IBookingDetailsEntity } from "../entity";
2
+ import { IModifyEntity } from "../modify-entity.interface";
3
+ export interface IGetTournamentResponse extends IModifyEntity<IBookingDetailsEntity> {
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -73,3 +73,5 @@ export * from "./get-cancelled-booking.interface";
73
73
  export * from "./get-sports.interface";
74
74
  export * from "../entity/sports-entity.interface";
75
75
  export * from "../api/update-sports-interface";
76
+ export * from "./get-availability-by-turf.interface";
77
+ export * from "./get-tournament.interface";
@@ -91,3 +91,5 @@ __exportStar(require("./get-cancelled-booking.interface"), exports);
91
91
  __exportStar(require("./get-sports.interface"), exports);
92
92
  __exportStar(require("../entity/sports-entity.interface"), exports);
93
93
  __exportStar(require("../api/update-sports-interface"), exports);
94
+ __exportStar(require("./get-availability-by-turf.interface"), exports);
95
+ __exportStar(require("./get-tournament.interface"), exports);
@@ -5,4 +5,10 @@ export interface IListOfCouponsResponse {
5
5
  unit: {
6
6
  values: number[];
7
7
  };
8
+ perHourUnit: {
9
+ values: number[];
10
+ };
11
+ perHourPercentage: {
12
+ values: number[];
13
+ };
8
14
  }
@@ -24,4 +24,6 @@ export interface IBookingDetailsEntity extends IEntityAuditColumn {
24
24
  amountPayable: number;
25
25
  refundPayable: number;
26
26
  totalRefundedAmount: number;
27
+ totalBookingHours: number;
28
+ type: string | null;
27
29
  }
@@ -1,5 +1,6 @@
1
1
  import { BookingDetailsStatus, PaymentMode, UserType } from "../@enum";
2
- export interface IGetBookingById {
2
+ import { IBookingDetailsEntity } from "./entity";
3
+ export interface IGetBookingById extends Omit<IBookingDetailsEntity, "createdBy" | "updatedBy"> {
3
4
  id: number;
4
5
  customerName: string;
5
6
  contact: string;
@@ -8,8 +9,6 @@ export interface IGetBookingById {
8
9
  totalCost: number;
9
10
  discountedCost: number;
10
11
  amountPaid: number;
11
- createdOn: Date;
12
- updatedOn: Date;
13
12
  createdBy: {
14
13
  firstname: string;
15
14
  type: UserType;
@@ -9,4 +9,5 @@ export interface IChargeModel {
9
9
  amountPayable: number;
10
10
  totalRefundedAmount: number;
11
11
  couponCode: string;
12
+ totalBookingHours: number;
12
13
  }
@@ -1,6 +1,6 @@
1
1
  import { IBookingDetailsWithBookingCodes, IChargeModel } from "../../@type";
2
2
  import { IModifyEntity } from "../modify-entity.interface";
3
- export interface BookingDetailsData extends IModifyEntity<IBookingDetailsWithBookingCodes>, IChargeModel {
3
+ export interface IBookingDetailsData extends IModifyEntity<IBookingDetailsWithBookingCodes>, IChargeModel {
4
4
  code?: string;
5
5
  slot_cost?: string;
6
6
  }
@@ -33,7 +33,7 @@ export declare class BookingCode {
33
33
  getCodeWithoutTurfCode(): string;
34
34
  static sortByCode(bookingCodes: BookingCode[]): void;
35
35
  static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
36
- static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean): number;
36
+ static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
37
37
  static getDiscountAmount(couponCode: string, totalCost: number): number;
38
38
  static isValidDate(date: string): boolean;
39
39
  static parseDateCode(dateCode: string): Date;
@@ -86,4 +86,24 @@ export declare class BookingCode {
86
86
  formatDateAndTime(formateDateAndTime: IFormateDateAndTime): string;
87
87
  static timeFormatter(timeFormatter: ITimeFormatter): string;
88
88
  static dateFormatter(dateFormatter: IDateFormatter): string;
89
+ /**
90
+ * Calculates the total time difference between two date codes.
91
+ * @param unit - Optional. Specifies the unit of time for the result. Valid values are "minute" or "hr". Defaults to "minute" if not provided.
92
+ * @returns The total time difference in the specified unit (minutes or hours) between the "from" and "to" date codes.
93
+ */
94
+ getTotalTime(unit?: "minute" | "hr"): number;
95
+ /**
96
+ * Gets the date codes across a time range.
97
+ *
98
+ * @returns An object containing the date codes for the from and to time.
99
+ * @description
100
+ * The `fromDateCode` is generated by combining the current instance's `dateCode` and `fromTimeCode`.
101
+ * The `toDateCode` is generated based on the `fromTimeCode` and `toTimeCode`. If `fromTimeCode` is greater
102
+ * than `toTimeCode`, it adds one day to the current instance's `dateCode`.
103
+ */
104
+ getAcrossDateCodes(): {
105
+ fromDateCode: string;
106
+ toDateCode: string;
107
+ };
108
+ static getTotalTimeByBookingCodes(bookingCodes: BookingCode[]): number;
89
109
  }
@@ -17,6 +17,7 @@ var charge_model_1 = require("./charge-model");
17
17
  var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
18
18
  var date_util_1 = require("../utils/date-util");
19
19
  var date_fns_1 = require("date-fns");
20
+ var _utils_1 = require("../@utils");
20
21
  var BookingCode = /** @class */ (function () {
21
22
  function BookingCode(code, cost) {
22
23
  if (cost === void 0) { cost = "-1"; }
@@ -116,12 +117,20 @@ var BookingCode = /** @class */ (function () {
116
117
  var code = turfId + bookingDate + fhfm + thtm + pitchCode;
117
118
  return code;
118
119
  };
119
- BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply) {
120
+ BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply, totalBookingHours) {
120
121
  if (validationApply === void 0) { validationApply = true; }
121
122
  var discount = 0;
122
123
  var discountedCost = 0;
123
124
  if (couponCode) {
124
- if (couponCode.endsWith("P")) {
125
+ var code = _utils_1.stringUtil.getCouponDetails(couponCode).code;
126
+ var value = _utils_1.stringUtil.getCouponDetails(couponCode).value;
127
+ if (validationApply && !code && !value) {
128
+ throw new app_badrequest_exception_1.AppBadRequestException({
129
+ key: "couponCode",
130
+ message: ["Coupon with code ".concat(couponCode, " is wrong ")],
131
+ });
132
+ }
133
+ if (code === "P" || code === "PHP") {
125
134
  var percentDiscount = parseFloat(couponCode);
126
135
  if (validationApply) {
127
136
  if (percentDiscount > 90) {
@@ -133,9 +142,20 @@ var BookingCode = /** @class */ (function () {
133
142
  }
134
143
  discount = totalCost * (percentDiscount / 100);
135
144
  }
136
- else if (couponCode.endsWith("U")) {
145
+ else if (code === "U") {
137
146
  discount = parseFloat(couponCode);
138
147
  }
148
+ else if (code === "PHU") {
149
+ if (totalBookingHours === undefined) {
150
+ throw new app_badrequest_exception_1.AppBadRequestException({
151
+ key: "totalBookingHours",
152
+ message: [
153
+ "Total Booking Hours is mandatory to calculate per hour unit",
154
+ ],
155
+ });
156
+ }
157
+ discount = parseFloat(couponCode) * totalBookingHours;
158
+ }
139
159
  }
140
160
  discountedCost = totalCost - discount;
141
161
  return Math.round(discountedCost);
@@ -504,6 +524,38 @@ var BookingCode = /** @class */ (function () {
504
524
  var dateFormat = dateFormatter.dateFormat, dateCode = dateFormatter.dateCode;
505
525
  return (0, date_fns_1.format)(BookingCode.convertToDate(dateCode), dateFormat);
506
526
  };
527
+ /**
528
+ * Calculates the total time difference between two date codes.
529
+ * @param unit - Optional. Specifies the unit of time for the result. Valid values are "minute" or "hr". Defaults to "minute" if not provided.
530
+ * @returns The total time difference in the specified unit (minutes or hours) between the "from" and "to" date codes.
531
+ */
532
+ BookingCode.prototype.getTotalTime = function (unit) {
533
+ if (unit === void 0) { unit = "minute"; }
534
+ return date_util_1.dateUtilService.calculateDateDifference(this.getAcrossDateCodes().fromDateCode, this.getAcrossDateCodes().toDateCode, unit);
535
+ };
536
+ /**
537
+ * Gets the date codes across a time range.
538
+ *
539
+ * @returns An object containing the date codes for the from and to time.
540
+ * @description
541
+ * The `fromDateCode` is generated by combining the current instance's `dateCode` and `fromTimeCode`.
542
+ * The `toDateCode` is generated based on the `fromTimeCode` and `toTimeCode`. If `fromTimeCode` is greater
543
+ * than `toTimeCode`, it adds one day to the current instance's `dateCode`.
544
+ */
545
+ BookingCode.prototype.getAcrossDateCodes = function () {
546
+ var fromDateCode = "".concat(this.dateCode).concat(this.fromTimeCode);
547
+ var toDateCode = "".concat(this.fromTimeCode > this.toTimeCode
548
+ ? date_util_1.dateUtilService.addNDaysToDateCode(this.dateCode, 1)
549
+ : this.dateCode).concat(this.toTimeCode);
550
+ return { fromDateCode: fromDateCode, toDateCode: toDateCode };
551
+ };
552
+ BookingCode.getTotalTimeByBookingCodes = function (bookingCodes) {
553
+ var totalBookingHours = 0;
554
+ bookingCodes.forEach(function (bookingCode) {
555
+ totalBookingHours += new BookingCode(bookingCode.code).getTotalTime("hr");
556
+ });
557
+ return totalBookingHours;
558
+ };
507
559
  return BookingCode;
508
560
  }());
509
561
  exports.BookingCode = BookingCode;
@@ -11,14 +11,15 @@ export declare class ChargesModel implements IChargeModel {
11
11
  amountPaid: number;
12
12
  amountPayable: number;
13
13
  totalRefundedAmount: number;
14
+ totalBookingHours: number;
14
15
  couponCode: string;
15
16
  discountPolicy: ModificationDiscountPolicy;
16
- constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, discountPolicy: ModificationDiscountPolicy);
17
+ constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, totalBookingHours: number, discountPolicy: ModificationDiscountPolicy);
17
18
  getGrossAmount(): number;
18
19
  getNetAmount(): number;
19
20
  getDiscountAmount(): number;
20
21
  getPayableRefundAmount(): number;
21
- static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
22
+ static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
22
23
  setValues(values?: Partial<ChargesModel>): ChargesModel;
23
24
  modify(bookingModification: IBookingModification): ChargesModel | null;
24
25
  private modifyExtend;
@@ -26,8 +27,7 @@ export declare class ChargesModel implements IChargeModel {
26
27
  private modifyMove;
27
28
  clone(): ChargesModel;
28
29
  private modifyDelete;
29
- static getInstance(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
30
- static assignByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
30
+ static getInstance(chargeData: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
31
31
  getTotalAmount(): number;
32
32
  getPaymentStatus(): "Refund" | "Paid" | "Pending";
33
33
  getTotalNetAmount(): number;
@@ -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;
@@ -185,32 +224,38 @@ var ChargesModel = /** @class */ (function () {
185
224
  }
186
225
  return newChargeModel;
187
226
  };
188
- ChargesModel.getInstance = function (bookingDetailsEntity, discountPolicy) {
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(bookingDetailsEntity.initialBookingGrossAmount, bookingDetailsEntity.amountPaid, bookingDetailsEntity.couponCode, discountPolicy);
191
- Object.assign(chargesModel, bookingDetailsEntity);
229
+ var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
230
+ Object.assign(chargesModel, chargeData);
192
231
  return chargesModel;
193
232
  };
194
- ChargesModel.assignByInterface = function (bookingDetailsEntity, discountPolicy) {
195
- if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
196
- var newChargeModel = new ChargesModel(bookingDetailsEntity.initialBookingGrossAmount, bookingDetailsEntity.amountPaid, bookingDetailsEntity.couponCode, discountPolicy);
197
- newChargeModel.additionalBookingGrossAmount =
198
- bookingDetailsEntity.additionalBookingGrossAmount;
199
- newChargeModel.initialBookingGrossAmount =
200
- bookingDetailsEntity.initialBookingGrossAmount;
201
- newChargeModel.cancelledBookingGrossAmount =
202
- bookingDetailsEntity.cancelledBookingGrossAmount;
203
- newChargeModel.refundPayable = bookingDetailsEntity.refundPayable;
204
- newChargeModel.totalRefundedAmount =
205
- bookingDetailsEntity.totalRefundedAmount;
206
- newChargeModel.amountPaid = bookingDetailsEntity.amountPaid;
207
- newChargeModel.totalCancellationCharges =
208
- bookingDetailsEntity.totalCancellationCharges;
209
- newChargeModel.netTotal = bookingDetailsEntity.netTotal;
210
- newChargeModel.couponCode = bookingDetailsEntity.couponCode;
211
- newChargeModel.amountPayable = bookingDetailsEntity.amountPayable;
212
- return newChargeModel;
213
- };
233
+ // static assignByInterface(
234
+ // chargeData: IChargeModel,
235
+ // discountPolicy: ModificationDiscountPolicy = ModificationDiscountPolicy.DISCOUNT_CONDITIONAL
236
+ // ): ChargesModel {
237
+ // const newChargeModel = new ChargesModel(
238
+ // chargeData.initialBookingGrossAmount,
239
+ // chargeData.amountPaid,
240
+ // chargeData.couponCode,
241
+ // discountPolicy
242
+ // );
243
+ // newChargeModel.additionalBookingGrossAmount =
244
+ // chargeData.additionalBookingGrossAmount;
245
+ // newChargeModel.initialBookingGrossAmount =
246
+ // chargeData.initialBookingGrossAmount;
247
+ // newChargeModel.cancelledBookingGrossAmount =
248
+ // chargeData.cancelledBookingGrossAmount;
249
+ // newChargeModel.refundPayable = chargeData.refundPayable;
250
+ // newChargeModel.totalRefundedAmount = chargeData.totalRefundedAmount;
251
+ // newChargeModel.amountPaid = chargeData.amountPaid;
252
+ // newChargeModel.totalCancellationCharges =
253
+ // chargeData.totalCancellationCharges;
254
+ // newChargeModel.netTotal = chargeData.netTotal;
255
+ // newChargeModel.couponCode = chargeData.couponCode;
256
+ // newChargeModel.amountPayable = chargeData.amountPayable;
257
+ // return newChargeModel;
258
+ // }
214
259
  ChargesModel.prototype.getTotalAmount = function () {
215
260
  return this.getNetAmount() + this.totalCancellationCharges;
216
261
  };
@@ -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,54 @@
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
+ constructor(data: IGetAvailabilityByTurf);
29
+ getTotalAvailablePrice(): number;
30
+ getTotalNonAvailablePrice(): number;
31
+ getTotalAvailableHours(): number;
32
+ getTotalNonAvailableHours(): number;
33
+ getSlots(): {
34
+ fromDate: number;
35
+ toDate: number;
36
+ from: string;
37
+ to: string;
38
+ weekdays: number[];
39
+ }[];
40
+ getPitchIds(): number[];
41
+ static fromJson(json: IGetAvailabilityByTurf): TurfAvailability;
42
+ static toJson(turfAvailability: TurfAvailability): IGetAvailabilityByTurf;
43
+ getTotalTime(): number;
44
+ getCode(): string;
45
+ parse(): void;
46
+ static parse(eventCode: string): {
47
+ pitchCodes: string[];
48
+ startDateCode: string;
49
+ endDateCode: string;
50
+ fromTimeCode: string;
51
+ toTimeCode: string;
52
+ };
53
+ }
54
+ export {};
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TurfAvailability = void 0;
4
+ var booking_code_model_1 = require("./booking-code-model");
5
+ var TurfAvailability = /** @class */ (function () {
6
+ function TurfAvailability(data) {
7
+ var _this = this;
8
+ this.data = data;
9
+ this.dateCodes = Object.keys(data).sort();
10
+ this.timeSlotCodesDateWise = {};
11
+ Object.entries(data).forEach(function (_a) {
12
+ var key = _a[0], value = _a[1];
13
+ _this.timeSlotCodesDateWise[key] = Object.keys(value).sort();
14
+ });
15
+ this.parse();
16
+ }
17
+ TurfAvailability.prototype.getTotalAvailablePrice = function () {
18
+ var totalCost = 0;
19
+ Object.entries(this.data).forEach(function (_a) {
20
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
21
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
22
+ var timeCode = _a[0], detailsPitchWise = _a[1];
23
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
24
+ var pitchCode = _a[0], details = _a[1];
25
+ if (!details.bookingId) {
26
+ totalCost += details.price;
27
+ }
28
+ });
29
+ });
30
+ });
31
+ return totalCost;
32
+ };
33
+ TurfAvailability.prototype.getTotalNonAvailablePrice = function () {
34
+ var totalCost = 0;
35
+ Object.entries(this.data).forEach(function (_a) {
36
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
37
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
38
+ var timeCode = _a[0], detailsPitchWise = _a[1];
39
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
40
+ var pitchCode = _a[0], details = _a[1];
41
+ if (details.bookingId !== undefined) {
42
+ totalCost += details.price;
43
+ }
44
+ });
45
+ });
46
+ });
47
+ return totalCost;
48
+ };
49
+ TurfAvailability.prototype.getTotalAvailableHours = function () {
50
+ var totalMinutes = 0;
51
+ Object.entries(this.data).forEach(function (_a) {
52
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
53
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
54
+ var timeCode = _a[0], detailsPitchWise = _a[1];
55
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
56
+ var pitchCode = _a[0], details = _a[1];
57
+ pitchCode = pitchCode.padStart(2, "0");
58
+ if (!details.bookingId) {
59
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
60
+ }
61
+ });
62
+ });
63
+ });
64
+ return totalMinutes / 60;
65
+ };
66
+ TurfAvailability.prototype.getTotalNonAvailableHours = function () {
67
+ var totalMinutes = 0;
68
+ Object.entries(this.data).forEach(function (_a) {
69
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
70
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
71
+ var timeCode = _a[0], detailsPitchWise = _a[1];
72
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
73
+ var pitchCode = _a[0], details = _a[1];
74
+ pitchCode = pitchCode.padStart(2, "0");
75
+ if (details.bookingId !== undefined) {
76
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
77
+ }
78
+ });
79
+ });
80
+ });
81
+ return totalMinutes / 60;
82
+ };
83
+ TurfAvailability.prototype.getSlots = function () {
84
+ this.dateCodes.sort(function (a, b) { return a.localeCompare(b); });
85
+ var fromDate = this.dateCodes[0];
86
+ var toDate = this.dateCodes[this.dateCodes.length - 1];
87
+ var fromDateTimeSlots = this.timeSlotCodesDateWise[fromDate];
88
+ var toDateTimeSlots = this.timeSlotCodesDateWise[toDate];
89
+ fromDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
90
+ toDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
91
+ var fromTime = fromDateTimeSlots[0].substring(0, 4);
92
+ var toTime = toDateTimeSlots[toDateTimeSlots.length - 1].substring(4, 8);
93
+ return [
94
+ {
95
+ fromDate: parseInt(fromDate, 10),
96
+ toDate: parseInt(toDate, 10),
97
+ from: fromTime,
98
+ to: toTime,
99
+ weekdays: [1, 2, 3, 4, 5, 6, 7],
100
+ },
101
+ ];
102
+ };
103
+ TurfAvailability.prototype.getPitchIds = function () {
104
+ var pitchIds = new Set();
105
+ var slots = this.getSlots();
106
+ if (this.data[slots[0].fromDate.toString()]) {
107
+ Object.entries(this.data[slots[0].fromDate.toString()]).forEach(function (_a) {
108
+ var timeCode = _a[0], detailsPitchWise = _a[1];
109
+ Object.keys(detailsPitchWise.details).forEach(function (pitchCode) {
110
+ pitchIds.add(parseInt(pitchCode, 10));
111
+ });
112
+ });
113
+ }
114
+ var pitchIdList = Array.from(pitchIds).sort(function (a, b) { return a - b; });
115
+ return pitchIdList;
116
+ };
117
+ TurfAvailability.fromJson = function (json) {
118
+ var data = {};
119
+ Object.entries(json).forEach(function (_a) {
120
+ var dateCode = _a[0], value = _a[1];
121
+ var dateData = {};
122
+ Object.entries(value).forEach(function (_a) {
123
+ var timeCode = _a[0], value = _a[1];
124
+ var timeSlotData = {};
125
+ Object.entries(value.details).forEach(function (_a) {
126
+ var pitchCode = _a[0], value = _a[1];
127
+ timeSlotData[pitchCode] = new TurfAvailabilityDetail({
128
+ price: value.price,
129
+ bookingId: value.bookingId,
130
+ status: value.status,
131
+ priceSlot: value.priceSlot,
132
+ });
133
+ });
134
+ dateData[timeCode] = new TurfAvailabilityBooking({
135
+ available: value.available,
136
+ notavailable: value.notavailable,
137
+ details: timeSlotData,
138
+ });
139
+ });
140
+ data[dateCode] = dateData;
141
+ });
142
+ return new TurfAvailability(data);
143
+ };
144
+ TurfAvailability.toJson = function (turfAvailability) {
145
+ var data = {};
146
+ Object.entries(turfAvailability.data).forEach(function (_a) {
147
+ var dateCode = _a[0], value = _a[1];
148
+ var dateData = {};
149
+ Object.entries(value).forEach(function (_a) {
150
+ var timeCode = _a[0], value = _a[1];
151
+ var timeSlotData = {};
152
+ Object.entries(value.details).forEach(function (_a) {
153
+ var pitchCode = _a[0], value = _a[1];
154
+ timeSlotData[pitchCode] = {
155
+ price: value.price,
156
+ bookingId: value.bookingId,
157
+ status: value.status,
158
+ priceSlot: value.priceSlot,
159
+ };
160
+ });
161
+ dateData[timeCode] = {
162
+ available: value.available,
163
+ notavailable: value.notavailable,
164
+ details: timeSlotData,
165
+ };
166
+ });
167
+ data[dateCode] = dateData;
168
+ });
169
+ return data;
170
+ };
171
+ TurfAvailability.prototype.getTotalTime = function () {
172
+ return this.getTotalAvailableHours() + this.getTotalNonAvailableHours();
173
+ };
174
+ TurfAvailability.prototype.getCode = function () {
175
+ 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());
176
+ };
177
+ TurfAvailability.prototype.parse = function () {
178
+ var eventCode = this.getCode();
179
+ var eventCodes = eventCode.split("#");
180
+ var dateCodeRange = eventCodes[1];
181
+ var timeCodeRange = eventCodes[2];
182
+ this.pitchCodes = eventCodes[3].split(",").map(function (id) { return id.padStart(2, "0"); });
183
+ this.startDateCode = dateCodeRange.slice(0, 6);
184
+ this.endDateCode = dateCodeRange.slice(6, 12);
185
+ this.fromTimeCode = timeCodeRange.slice(0, 4);
186
+ this.toTimeCode = timeCodeRange.slice(4, 8);
187
+ };
188
+ TurfAvailability.parse = function (eventCode) {
189
+ var eventCodes = eventCode.split("#");
190
+ var dateCodeRange = eventCodes[1];
191
+ var timeCodeRange = eventCodes[2];
192
+ return {
193
+ pitchCodes: eventCodes[3].split(",").map(function (id) { return id.padStart(2, "0"); }),
194
+ startDateCode: dateCodeRange.slice(0, 6),
195
+ endDateCode: dateCodeRange.slice(6, 12),
196
+ fromTimeCode: timeCodeRange.slice(0, 4),
197
+ toTimeCode: timeCodeRange.slice(4, 8),
198
+ };
199
+ };
200
+ return TurfAvailability;
201
+ }());
202
+ exports.TurfAvailability = TurfAvailability;
203
+ var TurfAvailabilityDetail = /** @class */ (function () {
204
+ function TurfAvailabilityDetail(_a) {
205
+ var price = _a.price, bookingId = _a.bookingId, status = _a.status, priceSlot = _a.priceSlot;
206
+ this.price = price;
207
+ this.bookingId = bookingId;
208
+ this.status = status;
209
+ this.priceSlot = priceSlot;
210
+ }
211
+ return TurfAvailabilityDetail;
212
+ }());
213
+ var TurfAvailabilityBooking = /** @class */ (function () {
214
+ function TurfAvailabilityBooking(_a) {
215
+ var available = _a.available, notavailable = _a.notavailable, details = _a.details;
216
+ this.available = available;
217
+ this.notavailable = notavailable;
218
+ this.details = details;
219
+ }
220
+ return TurfAvailabilityBooking;
221
+ }());
@@ -1 +1,2 @@
1
1
  export declare const SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
2
+ export declare const DEFAULT_PASSWORD = "turf@#123";
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
3
+ exports.DEFAULT_PASSWORD = exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = void 0;
4
4
  exports.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
5
+ exports.DEFAULT_PASSWORD = "turf@#123";
@@ -4,7 +4,7 @@ export declare class DateUtilService {
4
4
  getNDaysCode(n: number): string;
5
5
  getDateCode(date: Date): string;
6
6
  addNDaysToDate(date: Date, n: number): Date;
7
- convertStringToDate(dateString: string, format: string): Date;
7
+ convertStringToDate(dateString: string, format: string, timeZone?: string): Date;
8
8
  isInPast(date: Date): boolean;
9
9
  getDateFromDatabaseDate: (date: string) => Date;
10
10
  noOfDaysBetweenDates: (date1: Date, date2: Date) => number;
@@ -12,5 +12,25 @@ export declare class DateUtilService {
12
12
  formatTimeSlotCode(timeSlot: string, both?: boolean, date?: Date | null): string;
13
13
  formatDateCode(dateCode: string): string;
14
14
  getDateNDaysFromToday(n: number): Date;
15
+ calculateDateDifference(fromDateCode: string, toDateCode: string, unit?: "minute" | "hr"): number;
16
+ /**
17
+ * Adds or subtracts a specified number of months from a given date in YYMM format.
18
+ *
19
+ * @param {string} dateCode - A string representing a date in YYMM format.
20
+ * @param {number} N - An integer representing the number of months to add or subtract.
21
+ * Use a positive value to add months and a negative value to subtract months.
22
+ * @returns {string} A string representing the resulting date in YYMM format.
23
+ */
24
+ addNMonth(dateCode: string, N: number): string;
25
+ /**
26
+ * Gets an array of month codes between two specified dates (inclusive).
27
+ * 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.
28
+ *
29
+ * @param {string} startDateCode - The starting date code in "yyMMdd" format.
30
+ * @param {string} endDateCode - The ending date code in "yyMMdd" format.
31
+ * @returns {number[]} An array of month codes representing each month between the start and end dates (inclusive).
32
+ * Each element in the array is a number in the "yyMM" format.
33
+ */
34
+ getMonthRangeByDateCodes(startDateCode: string, endDateCode: string): number[];
15
35
  }
16
36
  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); };
@@ -23,8 +24,12 @@ var DateUtilService = /** @class */ (function () {
23
24
  DateUtilService.prototype.addNDaysToDate = function (date, n) {
24
25
  return (0, date_fns_1.add)(date, { days: n });
25
26
  };
26
- DateUtilService.prototype.convertStringToDate = function (dateString, format) {
27
- return (0, date_fns_1.parse)(dateString, format, new Date());
27
+ DateUtilService.prototype.convertStringToDate = function (dateString, format, timeZone) {
28
+ var parsedDate = (0, date_fns_1.parse)(dateString, format, new Date());
29
+ if (timeZone) {
30
+ return utcToZonedTime(parsedDate, timeZone);
31
+ }
32
+ return parsedDate;
28
33
  };
29
34
  DateUtilService.prototype.isInPast = function (date) {
30
35
  return date < new Date();
@@ -63,7 +68,52 @@ var DateUtilService = /** @class */ (function () {
63
68
  futureDate.setDate(today.getDate() + n);
64
69
  return futureDate;
65
70
  };
71
+ DateUtilService.prototype.calculateDateDifference = function (fromDateCode, toDateCode, unit) {
72
+ if (unit === void 0) { unit = "minute"; }
73
+ if (toDateCode.slice(-4, -2) === "24") {
74
+ toDateCode =
75
+ exports.dateUtilService.addNDaysToDateCode(toDateCode.slice(0, -4), 1) +
76
+ "00" +
77
+ toDateCode.slice(-2);
78
+ }
79
+ var fromDate = (0, date_fns_1.parse)(fromDateCode, "yyMMddHHmm", new Date());
80
+ var toDate = (0, date_fns_1.parse)(toDateCode, "yyMMddHHmm", new Date());
81
+ var minutesDifference = (0, date_fns_1.differenceInMinutes)(toDate, fromDate);
82
+ return unit === "minute"
83
+ ? minutesDifference
84
+ : parseFloat((minutesDifference / 60).toFixed(1));
85
+ };
86
+ /**
87
+ * Adds or subtracts a specified number of months from a given date in YYMM format.
88
+ *
89
+ * @param {string} dateCode - A string representing a date in YYMM format.
90
+ * @param {number} N - An integer representing the number of months to add or subtract.
91
+ * Use a positive value to add months and a negative value to subtract months.
92
+ * @returns {string} A string representing the resulting date in YYMM format.
93
+ */
94
+ DateUtilService.prototype.addNMonth = function (dateCode, N) {
95
+ var date = (0, date_fns_1.parse)("20".concat(dateCode), "yyyyMM", new Date());
96
+ var resultDate = N >= 0 ? (0, date_fns_1.addMonths)(date, N) : (0, date_fns_1.subMonths)(date, Math.abs(N));
97
+ return (0, date_fns_1.format)(resultDate, "yyMM");
98
+ };
99
+ /**
100
+ * Gets an array of month codes between two specified dates (inclusive).
101
+ * 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.
102
+ *
103
+ * @param {string} startDateCode - The starting date code in "yyMMdd" format.
104
+ * @param {string} endDateCode - The ending date code in "yyMMdd" format.
105
+ * @returns {number[]} An array of month codes representing each month between the start and end dates (inclusive).
106
+ * Each element in the array is a number in the "yyMM" format.
107
+ */
108
+ DateUtilService.prototype.getMonthRangeByDateCodes = function (startDateCode, endDateCode) {
109
+ var startDate = exports.dateUtilService.convertStringToDate(startDateCode, "yyMMdd");
110
+ var endDate = exports.dateUtilService.convertStringToDate(endDateCode, "yyMMdd");
111
+ return _model_1.BookingCode.getMonthCodesRange(startDate, endDate);
112
+ };
66
113
  return DateUtilService;
67
114
  }());
68
115
  exports.DateUtilService = DateUtilService;
69
116
  exports.dateUtilService = new DateUtilService();
117
+ function utcToZonedTime(parsedDate, timeZone) {
118
+ throw new Error("Function not implemented.");
119
+ }
@@ -14,6 +14,18 @@ declare class StringUtil {
14
14
  * @returns {string} - The formatted string with hyphens.
15
15
  */
16
16
  formatStringWithHyphens(inputString: string): string;
17
+ generateRandomPassword(): string;
18
+ /**
19
+ * Extracts details from a coupon code.
20
+ *
21
+ * @param {string} couponCode - The coupon code to analyze.
22
+ * @returns {Object} - Object with 'code' (alphabetic part) and 'value' (numeric part) properties.
23
+ * @throws {TypeError} - If the provided 'couponCode' is not a string.
24
+ */
25
+ getCouponDetails(couponCode: string): {
26
+ code: string;
27
+ value: string;
28
+ };
17
29
  }
18
30
  export declare const stringUtil: StringUtil;
19
31
  export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringUtil = void 0;
4
+ var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
4
5
  var StringUtil = /** @class */ (function () {
5
6
  function StringUtil() {
6
7
  }
@@ -24,6 +25,58 @@ var StringUtil = /** @class */ (function () {
24
25
  // Convert the input string to lowercase and replace spaces with hyphens
25
26
  return inputString.toLowerCase().replace(/\s+/g, "-");
26
27
  };
28
+ StringUtil.prototype.generateRandomPassword = function () {
29
+ var _a;
30
+ var alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
31
+ var numbers = "0123456789";
32
+ var specialChars = "!@#$%^&*?+";
33
+ function getRandomCharacter(characters) {
34
+ return characters[Math.floor(Math.random() * characters.length)];
35
+ }
36
+ var randomAlphabet = getRandomCharacter(alphabets);
37
+ var randomNumber = getRandomCharacter(numbers);
38
+ var randomSpecialChar = getRandomCharacter(specialChars);
39
+ var remainingCharacters = alphabets + alphabets.toLowerCase();
40
+ var randomRemainingChars = Array.from({ length: 3 }, function () {
41
+ return getRandomCharacter(remainingCharacters);
42
+ }).join("");
43
+ var passwordArray = [
44
+ randomAlphabet,
45
+ randomNumber,
46
+ randomSpecialChar,
47
+ randomRemainingChars,
48
+ ];
49
+ // Shuffle the password array
50
+ for (var i = passwordArray.length - 1; i > 0; i--) {
51
+ var j = Math.floor(Math.random() * (i + 1));
52
+ _a = [
53
+ passwordArray[j],
54
+ passwordArray[i],
55
+ ], passwordArray[i] = _a[0], passwordArray[j] = _a[1];
56
+ }
57
+ return passwordArray.join("");
58
+ };
59
+ /**
60
+ * Extracts details from a coupon code.
61
+ *
62
+ * @param {string} couponCode - The coupon code to analyze.
63
+ * @returns {Object} - Object with 'code' (alphabetic part) and 'value' (numeric part) properties.
64
+ * @throws {TypeError} - If the provided 'couponCode' is not a string.
65
+ */
66
+ StringUtil.prototype.getCouponDetails = function (couponCode) {
67
+ var code = couponCode.match(/[a-zA-Z]+/g);
68
+ var value = couponCode.match(/\d+/g);
69
+ if (!code || !value) {
70
+ throw new app_badrequest_exception_1.AppBadRequestException({
71
+ key: "couponCode",
72
+ message: ["coupon with code ".concat(couponCode, " is wrong ")],
73
+ });
74
+ }
75
+ return {
76
+ code: code[0],
77
+ value: value[0],
78
+ };
79
+ };
27
80
  return StringUtil;
28
81
  }());
29
82
  exports.stringUtil = new StringUtil();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turf-common",
3
- "version": "1.2.1-beta.5",
3
+ "version": "1.2.1-beta.50",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1 +0,0 @@
1
- export declare function FormatStringWithHyphens(inputString: string): string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatStringWithHyphens = void 0;
4
- function FormatStringWithHyphens(inputString) {
5
- return inputString.toLowerCase().replace(/\s+/g, "-");
6
- }
7
- exports.FormatStringWithHyphens = FormatStringWithHyphens;