turf-common 1.2.1-beta.2 → 1.2.1-beta.21

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.
package/build/@enum.d.ts CHANGED
@@ -22,3 +22,4 @@ 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";
package/build/@enum.js CHANGED
@@ -38,3 +38,4 @@ __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);
@@ -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 = {}));
@@ -24,4 +24,5 @@ export interface IBookingDetailsEntity extends IEntityAuditColumn {
24
24
  amountPayable: number;
25
25
  refundPayable: number;
26
26
  totalRefundedAmount: number;
27
+ totalBookingHours: number;
27
28
  }
@@ -1,5 +1,6 @@
1
1
  import { BookingDetailsStatus, PaymentMode, UserType } from "../@enum";
2
- export interface IGetBookingById {
2
+ import { IBankDetailsEntity } from "./entity";
3
+ export interface IGetBookingById extends Omit<IBankDetailsEntity, "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
- import { IBookingDetailsWithBookingCodes } from "../../@type";
1
+ import { IBookingDetailsWithBookingCodes, IChargeModel } from "../../@type";
2
2
  import { IModifyEntity } from "../modify-entity.interface";
3
- export interface BookingDetailsData extends IModifyEntity<IBookingDetailsWithBookingCodes> {
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 && (code[0] === "P" || code[0] === "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 && code[0] === "U") {
137
146
  discount = parseFloat(couponCode);
138
147
  }
148
+ else if (code && code[0] === "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;
@@ -1,7 +1,6 @@
1
1
  import { IBookingModification } from "../types/booking-modification.type";
2
2
  import { ModificationDiscountPolicy } from "../enums/modification-discount-policy.enum";
3
3
  import { IChargeModel } from "../interface/model/charge-model.interface";
4
- import { BookingDetailsData, IGetBookingDetailsByIdResponse } from "../@type";
5
4
  export declare class ChargesModel implements IChargeModel {
6
5
  initialBookingGrossAmount: number;
7
6
  additionalBookingGrossAmount: number;
@@ -12,14 +11,15 @@ export declare class ChargesModel implements IChargeModel {
12
11
  amountPaid: number;
13
12
  amountPayable: number;
14
13
  totalRefundedAmount: number;
14
+ totalBookingHours: number;
15
15
  couponCode: string;
16
16
  discountPolicy: ModificationDiscountPolicy;
17
- constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, discountPolicy: ModificationDiscountPolicy);
17
+ constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, totalBookingHours: number, discountPolicy: ModificationDiscountPolicy);
18
18
  getGrossAmount(): number;
19
19
  getNetAmount(): number;
20
20
  getDiscountAmount(): number;
21
21
  getPayableRefundAmount(): number;
22
- static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
22
+ static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
23
23
  setValues(values?: Partial<ChargesModel>): ChargesModel;
24
24
  modify(bookingModification: IBookingModification): ChargesModel | null;
25
25
  private modifyExtend;
@@ -27,14 +27,8 @@ export declare class ChargesModel implements IChargeModel {
27
27
  private modifyMove;
28
28
  clone(): ChargesModel;
29
29
  private modifyDelete;
30
- static getInstanceByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
31
- static assignByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
30
+ static getInstance(chargeData: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
32
31
  getTotalAmount(): number;
33
32
  getPaymentStatus(): "Refund" | "Paid" | "Pending";
34
- static getInstance(data: Partial<ChargesModel>, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
35
- static getInstanceByBookingDetailsData(bookingDetailsData: BookingDetailsData, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
36
- static getInstanceByBookingDetailData(bookingDetailData: IGetBookingDetailsByIdResponse, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
37
- static assignBookingDetailsData(existingData: Partial<ChargesModel>, bookingDetailsData: BookingDetailsData): Partial<ChargesModel>;
38
- static assignBookingDetailData(existingData: Partial<ChargesModel>, bookingDetailData: IGetBookingDetailsByIdResponse): Partial<ChargesModel>;
39
33
  getTotalNetAmount(): number;
40
34
  }
@@ -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 && (code[0] === "P" || code[0] === "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 && code[0] === "U") {
64
74
  discountAmount = parseFloat(couponCode);
65
75
  }
76
+ else if (code && code[0] === "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
  }
@@ -163,7 +188,7 @@ var ChargesModel = /** @class */ (function () {
163
188
  return newChargeModel;
164
189
  };
165
190
  ChargesModel.prototype.clone = function () {
166
- var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.discountPolicy);
191
+ var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.totalBookingHours, this.discountPolicy);
167
192
  Object.assign(that, this);
168
193
  return that;
169
194
  };
@@ -185,32 +210,38 @@ var ChargesModel = /** @class */ (function () {
185
210
  }
186
211
  return newChargeModel;
187
212
  };
188
- ChargesModel.getInstanceByInterface = function (bookingDetailsEntity, discountPolicy) {
213
+ ChargesModel.getInstance = function (chargeData, discountPolicy) {
189
214
  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);
215
+ var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
216
+ Object.assign(chargesModel, chargeData);
192
217
  return chargesModel;
193
218
  };
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
- };
219
+ // static assignByInterface(
220
+ // chargeData: IChargeModel,
221
+ // discountPolicy: ModificationDiscountPolicy = ModificationDiscountPolicy.DISCOUNT_CONDITIONAL
222
+ // ): ChargesModel {
223
+ // const newChargeModel = new ChargesModel(
224
+ // chargeData.initialBookingGrossAmount,
225
+ // chargeData.amountPaid,
226
+ // chargeData.couponCode,
227
+ // discountPolicy
228
+ // );
229
+ // newChargeModel.additionalBookingGrossAmount =
230
+ // chargeData.additionalBookingGrossAmount;
231
+ // newChargeModel.initialBookingGrossAmount =
232
+ // chargeData.initialBookingGrossAmount;
233
+ // newChargeModel.cancelledBookingGrossAmount =
234
+ // chargeData.cancelledBookingGrossAmount;
235
+ // newChargeModel.refundPayable = chargeData.refundPayable;
236
+ // newChargeModel.totalRefundedAmount = chargeData.totalRefundedAmount;
237
+ // newChargeModel.amountPaid = chargeData.amountPaid;
238
+ // newChargeModel.totalCancellationCharges =
239
+ // chargeData.totalCancellationCharges;
240
+ // newChargeModel.netTotal = chargeData.netTotal;
241
+ // newChargeModel.couponCode = chargeData.couponCode;
242
+ // newChargeModel.amountPayable = chargeData.amountPayable;
243
+ // return newChargeModel;
244
+ // }
214
245
  ChargesModel.prototype.getTotalAmount = function () {
215
246
  return this.getNetAmount() + this.totalCancellationCharges;
216
247
  };
@@ -222,50 +253,6 @@ var ChargesModel = /** @class */ (function () {
222
253
  ? "Paid"
223
254
  : "Pending";
224
255
  };
225
- ChargesModel.getInstance = function (data, discountPolicy) {
226
- if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
227
- var chargesModel = new ChargesModel(data.initialBookingGrossAmount, data.amountPaid, data.couponCode, discountPolicy);
228
- // set values
229
- Object.assign(chargesModel, data);
230
- return chargesModel;
231
- };
232
- ChargesModel.getInstanceByBookingDetailsData = function (bookingDetailsData, discountPolicy) {
233
- if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
234
- var data = ChargesModel.assignBookingDetailsData({}, bookingDetailsData);
235
- var chargesModel = new ChargesModel(data.initialBookingGrossAmount, data.amountPaid, data.couponCode, discountPolicy);
236
- // set values
237
- Object.assign(chargesModel, data);
238
- return chargesModel;
239
- };
240
- ChargesModel.getInstanceByBookingDetailData = function (bookingDetailData, discountPolicy) {
241
- if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
242
- var data = ChargesModel.assignBookingDetailData({}, bookingDetailData);
243
- var chargesModel = new ChargesModel(data.initialBookingGrossAmount, data.amountPaid, data.couponCode, discountPolicy);
244
- // set values
245
- Object.assign(chargesModel, data);
246
- return chargesModel;
247
- };
248
- ChargesModel.assignBookingDetailsData = function (existingData, bookingDetailsData) {
249
- Object.assign(existingData, bookingDetailsData);
250
- return existingData;
251
- };
252
- ChargesModel.assignBookingDetailData = function (existingData, bookingDetailData) {
253
- existingData.additionalBookingGrossAmount =
254
- bookingDetailData.additionalBookingGrossAmount;
255
- existingData.initialBookingGrossAmount =
256
- bookingDetailData.initialBookingGrossAmount;
257
- existingData.cancelledBookingGrossAmount =
258
- bookingDetailData.cancelledBookingGrossAmount;
259
- existingData.refundPayable = bookingDetailData.refundPayable;
260
- existingData.totalRefundedAmount = bookingDetailData.totalRefundedAmount;
261
- existingData.amountPaid = bookingDetailData.amountPaid;
262
- existingData.totalCancellationCharges =
263
- bookingDetailData.totalCancellationCharges;
264
- existingData.netTotal = bookingDetailData.netTotal;
265
- existingData.couponCode = bookingDetailData.couponCode;
266
- existingData.amountPayable = bookingDetailData.amountPayable;
267
- return existingData;
268
- };
269
256
  ChargesModel.prototype.getTotalNetAmount = function () {
270
257
  return this.getNetAmount() + this.totalCancellationCharges;
271
258
  };
@@ -32,6 +32,7 @@ export declare class BookingDetailsModel implements IBookingDetailsModel {
32
32
  updatedOn: Date;
33
33
  createdBy: number;
34
34
  updatedBy: number;
35
+ totalBookingHours: number;
35
36
  constructor(data: IBookingDetailsEntity);
36
37
  static getIdAndCreatedBy(bookingDetailsEntities: IBookingDetailsEntity[]): number[][];
37
38
  assignCharges(chargeModel: ChargesModel): void;
@@ -12,5 +12,6 @@ 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;
15
16
  }
16
17
  export declare const dateUtilService: DateUtilService;
@@ -63,6 +63,21 @@ var DateUtilService = /** @class */ (function () {
63
63
  futureDate.setDate(today.getDate() + n);
64
64
  return futureDate;
65
65
  };
66
+ DateUtilService.prototype.calculateDateDifference = function (fromDateCode, toDateCode, unit) {
67
+ if (unit === void 0) { unit = "minute"; }
68
+ if (toDateCode.slice(-4, -2) === "24") {
69
+ toDateCode =
70
+ exports.dateUtilService.addNDaysToDateCode(toDateCode.slice(0, -4), 1) +
71
+ "00" +
72
+ toDateCode.slice(-2);
73
+ }
74
+ var fromDate = (0, date_fns_1.parse)(fromDateCode, "yyMMddHHmm", new Date());
75
+ var toDate = (0, date_fns_1.parse)(toDateCode, "yyMMddHHmm", new Date());
76
+ var minutesDifference = (0, date_fns_1.differenceInMinutes)(toDate, fromDate);
77
+ return unit === "minute"
78
+ ? minutesDifference
79
+ : parseFloat((minutesDifference / 60).toFixed(1));
80
+ };
66
81
  return DateUtilService;
67
82
  }());
68
83
  exports.DateUtilService = DateUtilService;
@@ -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: RegExpMatchArray | null;
27
+ value: RegExpMatchArray | null;
28
+ };
17
29
  }
18
30
  export declare const stringUtil: StringUtil;
19
31
  export {};
@@ -24,6 +24,52 @@ var StringUtil = /** @class */ (function () {
24
24
  // Convert the input string to lowercase and replace spaces with hyphens
25
25
  return inputString.toLowerCase().replace(/\s+/g, "-");
26
26
  };
27
+ StringUtil.prototype.generateRandomPassword = function () {
28
+ var _a;
29
+ var alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
30
+ var numbers = "0123456789";
31
+ var specialChars = "!@#$%^&*?+";
32
+ function getRandomCharacter(characters) {
33
+ return characters[Math.floor(Math.random() * characters.length)];
34
+ }
35
+ var randomAlphabet = getRandomCharacter(alphabets);
36
+ var randomNumber = getRandomCharacter(numbers);
37
+ var randomSpecialChar = getRandomCharacter(specialChars);
38
+ var remainingCharacters = alphabets + alphabets.toLowerCase();
39
+ var randomRemainingChars = Array.from({ length: 3 }, function () {
40
+ return getRandomCharacter(remainingCharacters);
41
+ }).join("");
42
+ var passwordArray = [
43
+ randomAlphabet,
44
+ randomNumber,
45
+ randomSpecialChar,
46
+ randomRemainingChars,
47
+ ];
48
+ // Shuffle the password array
49
+ for (var i = passwordArray.length - 1; i > 0; i--) {
50
+ var j = Math.floor(Math.random() * (i + 1));
51
+ _a = [
52
+ passwordArray[j],
53
+ passwordArray[i],
54
+ ], passwordArray[i] = _a[0], passwordArray[j] = _a[1];
55
+ }
56
+ return passwordArray.join("");
57
+ };
58
+ /**
59
+ * Extracts details from a coupon code.
60
+ *
61
+ * @param {string} couponCode - The coupon code to analyze.
62
+ * @returns {Object} - Object with 'code' (alphabetic part) and 'value' (numeric part) properties.
63
+ * @throws {TypeError} - If the provided 'couponCode' is not a string.
64
+ */
65
+ StringUtil.prototype.getCouponDetails = function (couponCode) {
66
+ var code = couponCode.match(/[a-zA-Z]+/g);
67
+ var value = couponCode.match(/\d+/g);
68
+ return {
69
+ code: code,
70
+ value: value,
71
+ };
72
+ };
27
73
  return StringUtil;
28
74
  }());
29
75
  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.2",
3
+ "version": "1.2.1-beta.21",
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;