turf-common 1.4.2-beta.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/build/jest.config.js +2 -1
  2. package/build/src/@model.d.ts +1 -0
  3. package/build/src/@model.js +1 -0
  4. package/build/src/enums/booking-history-operation-type.enum.d.ts +4 -1
  5. package/build/src/enums/booking-history-operation-type.enum.js +3 -0
  6. package/build/src/enums/organization-status.enum.d.ts +4 -0
  7. package/build/src/enums/organization-status.enum.js +6 -1
  8. package/build/src/enums/transaction-type.enum.d.ts +2 -1
  9. package/build/src/enums/transaction-type.enum.js +1 -0
  10. package/build/src/enums/valid-coupon-type.enum.d.ts +3 -0
  11. package/build/src/enums/valid-coupon-type.enum.js +18 -0
  12. package/build/src/interface/api/booking-availablity-by-pitch.interface.d.ts +1 -0
  13. package/build/src/interface/api/booking-pending-payment-writeoff.interface.d.ts +10 -0
  14. package/build/src/interface/api/booking-pending-payment-writeoff.interface.js +2 -0
  15. package/build/src/interface/api/create-recurring-slot-booking.interface.d.ts +4 -1
  16. package/build/src/interface/api/create-user.interface.d.ts +1 -1
  17. package/build/src/interface/api/get-availability-by-turf.interface.d.ts +1 -0
  18. package/build/src/interface/api/get-booking-by-organization-id.interface.d.ts +1 -1
  19. package/build/src/interface/api/get-booking-history.interface.d.ts +1 -0
  20. package/build/src/interface/api/get-collection.interface.d.ts +1 -1
  21. package/build/src/interface/api/get-organization-configuration.interface.d.ts +8 -0
  22. package/build/src/interface/api/get-organization-configuration.interface.js +2 -0
  23. package/build/src/interface/api/index.d.ts +3 -0
  24. package/build/src/interface/api/index.js +3 -0
  25. package/build/src/interface/api/login-response.interface.d.ts +4 -1
  26. package/build/src/interface/api/one-slot-booking.interface.d.ts +2 -0
  27. package/build/src/interface/api/staff-member-list.interface.d.ts +1 -1
  28. package/build/src/interface/api/update-organization-configuration.interface.d.ts +6 -0
  29. package/build/src/interface/api/update-organization-configuration.interface.js +2 -0
  30. package/build/src/interface/api/update-recurring-booking.interface.d.ts +1 -0
  31. package/build/src/interface/api/update-staff-member.interface.d.ts +1 -1
  32. package/build/src/interface/entity/organization-entity.interface.d.ts +15 -3
  33. package/build/src/interface/entity/user-entity.interface.d.ts +6 -6
  34. package/build/src/interface/get-booking-by-id.interface.d.ts +2 -2
  35. package/build/src/interface/model/booking-details-model.interface.d.ts +8 -0
  36. package/build/src/interface/user-entity-essential-info.interface.d.ts +1 -1
  37. package/build/src/models/booking-code-model.d.ts +16 -2
  38. package/build/src/models/booking-code-model.js +83 -40
  39. package/build/src/models/charge-model.d.ts +2 -0
  40. package/build/src/models/charge-model.js +41 -11
  41. package/build/src/models/entity/booking-details-model.d.ts +2 -1
  42. package/build/src/models/entity/booking-details-model.js +19 -0
  43. package/build/src/models/entity/booking-entity-model.d.ts +1 -0
  44. package/build/src/models/entity/booking-entity-model.js +3 -0
  45. package/build/src/models/entity/user-model.d.ts +6 -6
  46. package/build/src/models/time-slot-model.d.ts +1 -0
  47. package/build/src/models/time-slot-model.js +3 -0
  48. package/build/src/models/turf-availability-model.d.ts +18 -3
  49. package/build/src/models/turf-availability-model.js +60 -3
  50. package/build/src/models/weekday-time-slot-model.d.ts +12 -0
  51. package/build/src/models/weekday-time-slot-model.js +30 -0
  52. package/build/src/utils/constant.d.ts +3 -0
  53. package/build/src/utils/constant.js +4 -1
  54. package/build/src/utils/date-util.d.ts +8 -1
  55. package/build/src/utils/date-util.js +22 -3
  56. package/build/tests/booking-code/method.spec.d.ts +1 -0
  57. package/build/tests/booking-code/method.spec.js +11 -0
  58. package/build/tests/unit/charges/discount-relative/basic.spec.d.ts +1 -0
  59. package/build/tests/unit/charges/discount-relative/basic.spec.js +209 -0
  60. package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.d.ts +1 -0
  61. package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.js +208 -0
  62. package/build/tests/unit/charges/extension/basic.spec.d.ts +1 -0
  63. package/build/tests/unit/charges/extension/basic.spec.js +215 -0
  64. package/build/tests/unit/pricing-plan/basic-scenario.spec.js +1 -1
  65. package/package.json +54 -43
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // Sync object
4
4
  var config = {
5
- verbose: true,
5
+ // verbose: true,
6
6
  transform: {
7
7
  "^.+\\.tsx?$": "ts-jest",
8
8
  },
9
+ testMatch: ["**/tests/**/*.spec.ts"],
9
10
  };
10
11
  exports.default = config;
@@ -7,3 +7,4 @@ export * from "./models/pricing-plan-model";
7
7
  export * from "./models/subscribed-pricing-plan-model";
8
8
  export * from "./models/entity";
9
9
  export * from "./models/turf-availability-model";
10
+ export * from "./models/weekday-time-slot-model";
@@ -23,3 +23,4 @@ __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
25
  __exportStar(require("./models/turf-availability-model"), exports);
26
+ __exportStar(require("./models/weekday-time-slot-model"), exports);
@@ -7,6 +7,9 @@ export declare enum BookingHistoryOperationType {
7
7
  REFUND = "refund",
8
8
  PAYMENT = "payment",
9
9
  MERGED = "merged",
10
- DELETE_SLOT_EVENT = "delete_slot_event"
10
+ DELETE_SLOT_EVENT = "delete_slot_event",
11
+ EXTENSION = "extension",
12
+ PAYMENT_WRITEOFF = "payment_writeoff",
13
+ EXTENSION_MERGED = "extension_merged"
11
14
  }
12
15
  export declare const OPERATION_TYPES: BookingHistoryOperationType[];
@@ -12,6 +12,9 @@ var BookingHistoryOperationType;
12
12
  BookingHistoryOperationType["PAYMENT"] = "payment";
13
13
  BookingHistoryOperationType["MERGED"] = "merged";
14
14
  BookingHistoryOperationType["DELETE_SLOT_EVENT"] = "delete_slot_event";
15
+ BookingHistoryOperationType["EXTENSION"] = "extension";
16
+ BookingHistoryOperationType["PAYMENT_WRITEOFF"] = "payment_writeoff";
17
+ BookingHistoryOperationType["EXTENSION_MERGED"] = "extension_merged";
15
18
  })(BookingHistoryOperationType || (exports.BookingHistoryOperationType = BookingHistoryOperationType = {}));
16
19
  exports.OPERATION_TYPES = [
17
20
  BookingHistoryOperationType.DELETE,
@@ -13,3 +13,7 @@ export declare namespace OrganizationStatus {
13
13
  function allowPermissionSuperAdmin(): OrganizationStatus[];
14
14
  function allowPermissionOwner(): OrganizationStatus[];
15
15
  }
16
+ export declare enum AllowManualBookingDiscount {
17
+ YES = "yes",
18
+ NO = "no"
19
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrganizationStatus = void 0;
3
+ exports.AllowManualBookingDiscount = exports.OrganizationStatus = void 0;
4
4
  var OrganizationStatus;
5
5
  (function (OrganizationStatus) {
6
6
  OrganizationStatus["REGISTRATION"] = "registration";
@@ -29,3 +29,8 @@ var OrganizationStatus;
29
29
  }
30
30
  OrganizationStatus.allowPermissionOwner = allowPermissionOwner;
31
31
  })(OrganizationStatus || (exports.OrganizationStatus = OrganizationStatus = {}));
32
+ var AllowManualBookingDiscount;
33
+ (function (AllowManualBookingDiscount) {
34
+ AllowManualBookingDiscount["YES"] = "yes";
35
+ AllowManualBookingDiscount["NO"] = "no";
36
+ })(AllowManualBookingDiscount || (exports.AllowManualBookingDiscount = AllowManualBookingDiscount = {}));
@@ -3,5 +3,6 @@ export declare enum BookingPaymentTransactionType {
3
3
  CUSTOMER_REFUND = "customer_refund",
4
4
  CUSTOMER_REFUND_INPROCESS = "customer_refund_inprocess",
5
5
  CUSTOMER_REFUND_REJECT = "customer_refund_reject",
6
- CUSTOMER_CANCELLATION = "customer_cancellation"
6
+ CUSTOMER_CANCELLATION = "customer_cancellation",
7
+ PAYMENT_WRITEOFF = "payment_writeoff"
7
8
  }
@@ -8,4 +8,5 @@ var BookingPaymentTransactionType;
8
8
  BookingPaymentTransactionType["CUSTOMER_REFUND_INPROCESS"] = "customer_refund_inprocess";
9
9
  BookingPaymentTransactionType["CUSTOMER_REFUND_REJECT"] = "customer_refund_reject";
10
10
  BookingPaymentTransactionType["CUSTOMER_CANCELLATION"] = "customer_cancellation";
11
+ BookingPaymentTransactionType["PAYMENT_WRITEOFF"] = "payment_writeoff";
11
12
  })(BookingPaymentTransactionType || (exports.BookingPaymentTransactionType = BookingPaymentTransactionType = {}));
@@ -4,3 +4,6 @@ export declare enum ValidCouponType {
4
4
  PER_HOUR_UNIT = "per hour unit",
5
5
  PER_HOUR_PERCENTAGE = "per hour percentage"
6
6
  }
7
+ export declare namespace ValidCouponType {
8
+ function UILabel(value: ValidCouponType): string;
9
+ }
@@ -8,3 +8,21 @@ var ValidCouponType;
8
8
  ValidCouponType["PER_HOUR_UNIT"] = "per hour unit";
9
9
  ValidCouponType["PER_HOUR_PERCENTAGE"] = "per hour percentage";
10
10
  })(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
11
+ // Create namespace for the enum and add method UILabel to get the label of the enum value.
12
+ (function (ValidCouponType) {
13
+ function UILabel(value) {
14
+ switch (value) {
15
+ case ValidCouponType.PERCENTAGE:
16
+ return "Percentage";
17
+ case ValidCouponType.UNIT:
18
+ return "Price";
19
+ case ValidCouponType.PER_HOUR_UNIT:
20
+ return "Price Hour Unit";
21
+ case ValidCouponType.PER_HOUR_PERCENTAGE:
22
+ return "Per Hour Percentage";
23
+ default:
24
+ return "";
25
+ }
26
+ }
27
+ ValidCouponType.UILabel = UILabel;
28
+ })(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
@@ -36,4 +36,5 @@ export interface IBookingAvailabilitySlotRequest {
36
36
  weekdays: number[];
37
37
  from: string;
38
38
  to: string;
39
+ pitchNo: number;
39
40
  }
@@ -0,0 +1,10 @@
1
+ export interface BookingPendingPaymentWriteoffRequest {
2
+ bookingDetailIds: number[];
3
+ totalWriteoffAmount: number;
4
+ remark: string;
5
+ }
6
+ export interface BookingPendingPaymentWriteoffResponse {
7
+ bookingDetailIds: number[];
8
+ totalWriteoffAmount: number;
9
+ remark: string;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { PaymentMode, BookingDetailsStatus } from "../../@enum";
2
- import { IBookingDetailsEntity, IGetAvailabilityByTurf, IModifyEntity } from "../../@type";
2
+ import { IBookingDetailsEntity, IGetAvailabilityByTurf, IGetAvailabilityByTurfRequest, IModifyEntity } from "../../@type";
3
3
  export interface ICreateRecurringSlotBookingResponse extends IModifyEntity<IBookingDetailsEntity> {
4
4
  }
5
5
  export interface ICreateRecurringSlotsBookingDetailsRequest {
@@ -18,7 +18,9 @@ export interface ICreateRecurringSlotsBookingDetailsRequest {
18
18
  slot: IRecurringSlot[];
19
19
  turf_slot?: {
20
20
  availability_details: IGetAvailabilityByTurf;
21
+ apiRequestModel?: IGetAvailabilityByTurfRequest;
21
22
  };
23
+ deleteIntermediateBookings: boolean;
22
24
  }
23
25
  export declare class IRecurringSlot {
24
26
  fromDate: number;
@@ -26,4 +28,5 @@ export declare class IRecurringSlot {
26
28
  weekdays: number[];
27
29
  from: string;
28
30
  to: string;
31
+ pitchNo: number;
29
32
  }
@@ -1,6 +1,6 @@
1
1
  import { UserType } from "../../@enum";
2
2
  export interface IUserRequest {
3
- firstname: string;
3
+ name: string;
4
4
  password: string;
5
5
  phone: number;
6
6
  email?: string;
@@ -6,6 +6,7 @@ export interface IGetAvailabilityByTurfRequest {
6
6
  pitch: string;
7
7
  view: AvailabilityView;
8
8
  weekDays: number[];
9
+ weekdayTimeSlots: string[];
9
10
  }
10
11
  export interface IGetAvailabilityByTurf {
11
12
  [dateCode: string]: IAvailabilityData;
@@ -19,7 +19,7 @@ export interface IGetBookingsByOrganizationIdResponse {
19
19
  user: {
20
20
  [userId: string]: {
21
21
  id: number;
22
- firstname: string;
22
+ name: string;
23
23
  email: string;
24
24
  type: UserType;
25
25
  };
@@ -1,4 +1,5 @@
1
1
  import { IBookingHistoryEntity } from "../entity";
2
2
  export interface IGetBookingHistoryResponse extends IBookingHistoryEntity {
3
3
  text: string;
4
+ createdByUsername: string;
4
5
  }
@@ -8,7 +8,7 @@ export interface IGetCollectionResponse {
8
8
  }>;
9
9
  };
10
10
  users: {
11
- [key: number]: Pick<IUserEntity, "id" | "firstname" | "phone" | "email" | "type">;
11
+ [key: number]: Pick<IUserEntity, "id" | "name" | "phone" | "email" | "type">;
12
12
  };
13
13
  total: IDateWisePaymentHistoryData;
14
14
  payments: Modify<IBookingPaymentHistoryEntity, {
@@ -0,0 +1,8 @@
1
+ export interface IGetOrganizationConfigurationResponse {
2
+ [key: string]: {
3
+ key: string;
4
+ value: string;
5
+ text: string;
6
+ description: string;
7
+ };
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -76,3 +76,6 @@ export * from "../api/update-sports-interface";
76
76
  export * from "./get-availability-by-turf.interface";
77
77
  export * from "./get-tournament.interface";
78
78
  export * from "./get-booking-history.interface";
79
+ export * from "./booking-pending-payment-writeoff.interface";
80
+ export * from "./get-organization-configuration.interface";
81
+ export * from "./update-organization-configuration.interface";
@@ -94,3 +94,6 @@ __exportStar(require("../api/update-sports-interface"), exports);
94
94
  __exportStar(require("./get-availability-by-turf.interface"), exports);
95
95
  __exportStar(require("./get-tournament.interface"), exports);
96
96
  __exportStar(require("./get-booking-history.interface"), exports);
97
+ __exportStar(require("./booking-pending-payment-writeoff.interface"), exports);
98
+ __exportStar(require("./get-organization-configuration.interface"), exports);
99
+ __exportStar(require("./update-organization-configuration.interface"), exports);
@@ -1,9 +1,10 @@
1
+ import { IOrganizationConfig } from "../entity";
1
2
  export interface ILoginResponse {
2
3
  UIMessage: string;
3
4
  tokenType: string;
4
5
  accessToken: string;
5
6
  id: string;
6
- firstname: string;
7
+ name: string;
7
8
  status: string;
8
9
  requireNewPassword: boolean;
9
10
  userId: number;
@@ -15,6 +16,8 @@ export interface ILoginResponse {
15
16
  organizationId: number;
16
17
  subscriptionStatus: string | null;
17
18
  contact: string;
19
+ orgConfig: IOrganizationConfig;
20
+ registrationFlowVersion?: number | null;
18
21
  }
19
22
  export interface ILoginRequest {
20
23
  username: string;
@@ -12,6 +12,7 @@ export interface ICreateOneSlotBookingDetailsRequest {
12
12
  discountedCost: number;
13
13
  amountPaid: number;
14
14
  pitchId: number;
15
+ pitchIds?: number[];
15
16
  status: BookingDetailsStatus;
16
17
  sport: string;
17
18
  remarks?: string | null;
@@ -21,4 +22,5 @@ export interface ICreateOneSlot {
21
22
  date: number;
22
23
  from: string;
23
24
  to: string;
25
+ pitchNo: number;
24
26
  }
@@ -1,7 +1,7 @@
1
1
  import { UserStatus } from "../../@enum";
2
2
  export interface IStaffMemberListResponse {
3
3
  id: number;
4
- firstname: string;
4
+ name: string;
5
5
  phone: string;
6
6
  email: string;
7
7
  status: UserStatus;
@@ -0,0 +1,6 @@
1
+ export interface IUpdateOrganizationConfigurationResponse extends Array<IUpdateOrganizationConfigurationRequest> {
2
+ }
3
+ export interface IUpdateOrganizationConfigurationRequest {
4
+ key: string;
5
+ value: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -34,6 +34,7 @@ export interface IUpdateRecurringBookingResponse extends IModifyEntity<IBookingD
34
34
  discountPolicy?: string;
35
35
  delete_slot?: IDeleteBookingByCodesDto;
36
36
  update_slot?: IUpdateBookingByCodesDto;
37
+ extension_booking_codes?: string[];
37
38
  }
38
39
  export interface IUpdateRecurringSlotBookingDetailsRequest {
39
40
  customerName?: string;
@@ -7,7 +7,7 @@ export interface IUpdateStaffMemberResponse extends Modify<Omit<IUserEntity, "pa
7
7
  turfids?: string[];
8
8
  }
9
9
  export interface IUpdateStaffMemberRequest {
10
- firstname?: string;
10
+ name?: string;
11
11
  lastname?: string;
12
12
  phone?: number;
13
13
  turfids?: string[];
@@ -1,9 +1,16 @@
1
- import { OrganizationType } from "../../@enum";
2
- import { OrganizationStatus } from "../../enums/organization-status.enum";
1
+ import { ModificationDiscountPolicy, OrganizationType } from "../../@enum";
2
+ import { AllowManualBookingDiscount, OrganizationStatus } from "../../enums/organization-status.enum";
3
3
  import { ICouponEntity } from "./coupon.entity.interface";
4
4
  import { IEntityAuditColumn } from "./entity-audit-column.interface";
5
5
  import { ITurfEntity } from "./turf-entity.interface";
6
- export interface IOrganizationEntity extends IEntityAuditColumn, IOrganizationEntityRel {
6
+ export interface IOrganizationConfig {
7
+ allowManualBookingDiscount: AllowManualBookingDiscount;
8
+ bookingCreationDelay: number;
9
+ bookingModificationDelay: number;
10
+ bookingCancellationDelay: number;
11
+ modificationDiscountPolicy: ModificationDiscountPolicy;
12
+ }
13
+ export interface IOrganizationEntity extends IEntityAuditColumn, IOrganizationEntityRel, IOrganizationConfig {
7
14
  id: number;
8
15
  name: string;
9
16
  email: string | null;
@@ -17,6 +24,11 @@ export interface IOrganizationEntity extends IEntityAuditColumn, IOrganizationEn
17
24
  deed_file_path: string | null;
18
25
  status: OrganizationStatus;
19
26
  registrationId: number;
27
+ allowManualBookingDiscount: AllowManualBookingDiscount;
28
+ bookingCreationDelay: number;
29
+ bookingModificationDelay: number;
30
+ bookingCancellationDelay: number;
31
+ modificationDiscountPolicy: ModificationDiscountPolicy;
20
32
  }
21
33
  export interface IOrganizationEntityRel {
22
34
  turfs: ITurfEntity[];
@@ -4,16 +4,16 @@ import { UserType } from "../../enums/valid-type.enum";
4
4
  import { ITurfEntity } from "./turf-entity.interface";
5
5
  export interface IUserEntity extends IEntityAuditColumn, IUserEntityRel {
6
6
  id: number;
7
- firstname: string;
7
+ name: string;
8
8
  phone: string;
9
9
  password: string;
10
10
  email: string;
11
11
  status: UserStatus;
12
- is_email_verified: boolean;
13
- is_mobile_verified: boolean;
14
- is_account_verified: boolean;
15
- require_new_password: boolean;
16
- organization_id: number;
12
+ isEmailVerified: boolean;
13
+ isMobileVerified: boolean;
14
+ isAccountVerified: boolean;
15
+ requireNewPassword: boolean;
16
+ organizationId: number;
17
17
  type: UserType;
18
18
  registrationId: number;
19
19
  comments: string | null;
@@ -10,12 +10,12 @@ export interface IGetBookingById extends Omit<IBookingDetailsEntity, "createdBy"
10
10
  discountedCost: number;
11
11
  amountPaid: number;
12
12
  createdBy: {
13
- firstname: string;
13
+ name: string;
14
14
  type: UserType;
15
15
  id: number;
16
16
  };
17
17
  updatedBy: {
18
- firstname: string;
18
+ name: string;
19
19
  type: UserType;
20
20
  id: number;
21
21
  };
@@ -1,5 +1,13 @@
1
+ import { WeekdayTimeSlot } from "../../@model";
1
2
  import { ChargesModel } from "../../models/charge-model";
2
3
  import { IBookingDetailsEntity } from "../entity/booking-details-entity.interface";
4
+ export interface IEventBookingDetails {
5
+ startDateCode: number;
6
+ endDateCode: number;
7
+ weekdaySlots: WeekdayTimeSlot[];
8
+ pitchIds: number[];
9
+ }
3
10
  export interface IBookingDetailsModel extends IBookingDetailsEntity {
4
11
  assignCharges(chargeModel: ChargesModel): void;
12
+ getEventDetails(): IEventBookingDetails;
5
13
  }
@@ -1,3 +1,3 @@
1
1
  import { IUserEntity } from "./entity";
2
- export interface IUserEntityEssentialInfo extends Pick<IUserEntity, "id" | "firstname" | "phone" | "email" | "type"> {
2
+ export interface IUserEntityEssentialInfo extends Pick<IUserEntity, "id" | "name" | "phone" | "email" | "type"> {
3
3
  }
@@ -20,7 +20,7 @@ export declare class BookingCode {
20
20
  getHalfHourTimeCodes(): string[];
21
21
  /**
22
22
  *
23
- * @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
23
+ * @returns ['00000030','00300100','01000130']: string[] - List of half hour time slot codes between start time & end time inclusive
24
24
  * @example fromTime: 0000; toTime: 0130
25
25
  * // returns ['00000030','00300100','01000130']
26
26
  */
@@ -30,7 +30,18 @@ export declare class BookingCode {
30
30
  getWeekday(): number;
31
31
  getMonthCode(): string;
32
32
  getDateWithFromTimeCode(): string;
33
+ getDateWithToTimeCode(): string;
33
34
  getCodeWithoutTurfCode(): string;
35
+ getPriceByPriceEntities(priceEntities?: {
36
+ [date: string]: {
37
+ [time: string]: number;
38
+ };
39
+ }): number;
40
+ getToDate(): Date;
41
+ isAcrossDate(): boolean;
42
+ isModificationAllowed(delayInMinutes?: number): boolean;
43
+ isDeletionAllowed(delayInMinutes?: number): boolean;
44
+ isCreationAllowed(delayInMinutes?: number): boolean;
34
45
  static sortByCode(bookingCodes: BookingCode[]): void;
35
46
  static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
36
47
  static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
@@ -40,12 +51,13 @@ export declare class BookingCode {
40
51
  static getWeekday(dateCode: number): number;
41
52
  static convertToDate(str: string): Date;
42
53
  static previousDateChecker(fromDate: number, index: number, errorKey?: string): void;
43
- static previousTimeChecker(fromTime: string, fromDate: number, index: number): void;
54
+ static previousTimeChecker(fromTime: string, fromDate: number, index: number, bookingDelayInMinutes?: number, date?: Date): void;
44
55
  static getDateCodesByWeek(fromDate: number, toDate: number, selectedWeekday: number): string[];
45
56
  static getDatesByWeek(fromDate: number, toDate: number, selectedWeekday: number): Date[];
46
57
  static isValidTimeRange(timeSlot: string): boolean;
47
58
  static dateFormat(dates: Array<Date>): Array<string>;
48
59
  static getDateCode(date: Date): string;
60
+ static getMonthCode(date: Date): number;
49
61
  /**
50
62
  * Returns list of month codes (YYMM) in the Date range inclusive
51
63
  * @param {Date} from - Start Date
@@ -136,4 +148,6 @@ export declare class BookingCode {
136
148
  * Additionally, the pitch number and turf ID must match between the two codes.
137
149
  */
138
150
  isAdjacentBookingCode(nextBookingCode: BookingCode): boolean;
151
+ static getInstanceByComponents(turfId: number, pitchCode: number, dateCode: number, fromTimeCode: string, toTimeCode: string, priceCsv: string): BookingCode;
152
+ isTimeSlotContinuous(that: BookingCode): boolean;
139
153
  }
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.BookingCode = void 0;
15
4
  var time_slot_model_1 = require("./time-slot-model");
@@ -60,7 +49,7 @@ var BookingCode = /** @class */ (function () {
60
49
  };
61
50
  /**
62
51
  *
63
- * @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
52
+ * @returns ['00000030','00300100','01000130']: string[] - List of half hour time slot codes between start time & end time inclusive
64
53
  * @example fromTime: 0000; toTime: 0130
65
54
  * // returns ['00000030','00300100','01000130']
66
55
  */
@@ -102,9 +91,54 @@ var BookingCode = /** @class */ (function () {
102
91
  BookingCode.prototype.getDateWithFromTimeCode = function () {
103
92
  return "".concat(this.dateCode).concat(this.fromTimeCode);
104
93
  };
94
+ BookingCode.prototype.getDateWithToTimeCode = function () {
95
+ return "".concat(this.dateCode).concat(this.toTimeCode);
96
+ };
105
97
  BookingCode.prototype.getCodeWithoutTurfCode = function () {
106
98
  return "".concat(this.dateCode).concat(this.slot).concat(this.pitchCode);
107
99
  };
100
+ BookingCode.prototype.getPriceByPriceEntities = function (priceEntities) {
101
+ var halfHourTimeRangeCodes = this.getHalfHourTimeRangeCodes();
102
+ var weekDay = this.getWeekday();
103
+ var monthCode = this.getMonthCode();
104
+ var price = 0;
105
+ for (var _i = 0, halfHourTimeRangeCodes_1 = halfHourTimeRangeCodes; _i < halfHourTimeRangeCodes_1.length; _i++) {
106
+ var halfHourTimeRangeCode = halfHourTimeRangeCodes_1[_i];
107
+ price +=
108
+ priceEntities[monthCode + weekDay][halfHourTimeRangeCode] < 0 ? 0 : priceEntities[monthCode + weekDay][halfHourTimeRangeCode];
109
+ }
110
+ return price;
111
+ };
112
+ BookingCode.prototype.getToDate = function () {
113
+ return date_util_1.dateUtilService.convertStringToDate(this.getDateWithToTimeCode(), "yyMMddHHmm");
114
+ };
115
+ BookingCode.prototype.isAcrossDate = function () {
116
+ return this.fromTimeCode > this.toTimeCode;
117
+ };
118
+ BookingCode.prototype.isModificationAllowed = function (delayInMinutes) {
119
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_MODIFICATION_DELAY_IN_MINUTES; }
120
+ var dateWithToTimeCode = this.getDateWithToTimeCode();
121
+ // If last four digits of dateWithToTimeCode is 2400, then replace it with 2359
122
+ if (dateWithToTimeCode.slice(-4) === _utils_1.END_OF_DAY_TIME_CODE) {
123
+ dateWithToTimeCode = dateWithToTimeCode.slice(0, -4) + "2359";
124
+ }
125
+ var toDate = date_util_1.dateUtilService.convertStringToDate(dateWithToTimeCode, "yyMMddHHmm");
126
+ var bookingToDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(toDate, delayInMinutes + (this.isAcrossDate() ? 24 * 60 : 0));
127
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
128
+ return bookingToDateTimeWithDelay > currentTime;
129
+ };
130
+ BookingCode.prototype.isDeletionAllowed = function (delayInMinutes) {
131
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_DELETION_DELAY_IN_MINUTES; }
132
+ var bookingFromDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(date_util_1.dateUtilService.convertStringToDate(this.getDateWithFromTimeCode(), "yyMMddHHmm"), delayInMinutes);
133
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
134
+ return bookingFromDateTimeWithDelay > currentTime;
135
+ };
136
+ BookingCode.prototype.isCreationAllowed = function (delayInMinutes) {
137
+ if (delayInMinutes === void 0) { delayInMinutes = _utils_1.DEFAULT_BOOKING_DELAY_IN_MINUTES; }
138
+ var bookingFromDateTimeWithDelay = date_util_1.dateUtilService.addMinutesTo(date_util_1.dateUtilService.convertStringToDate(this.getDateWithFromTimeCode(), "yyMMddHHmm"), delayInMinutes);
139
+ var currentTime = date_util_1.dateUtilService.getIndianDate();
140
+ return bookingFromDateTimeWithDelay > currentTime;
141
+ };
108
142
  BookingCode.sortByCode = function (bookingCodes) {
109
143
  bookingCodes.sort(function (_a, _b) {
110
144
  var code1 = _a.code;
@@ -221,26 +255,17 @@ var BookingCode = /** @class */ (function () {
221
255
  }
222
256
  };
223
257
  //---------------------
224
- BookingCode.previousTimeChecker = function (fromTime, fromDate, index) {
225
- var now = new Date();
226
- this.convertToDate(fromDate.toString());
227
- var delayInBooking = 15;
228
- if (this.convertToDate(fromDate.toString()) > now) {
229
- return; //do nothing if fromDate is in future
230
- }
231
- else if (this.convertToDate(fromDate.toString()) <= now) {
232
- now.setMinutes(now.getMinutes() - delayInBooking); // 15minutes buffer for late bookings
233
- var options = {
234
- timeZone: "Asia/Kolkata",
235
- };
236
- var timeFormat = new Intl.DateTimeFormat("en-US", __assign(__assign({}, options), { hour: "2-digit", minute: "2-digit", hour12: false }));
237
- var currentTimeObj = timeFormat.format(now).replace(/:/g, "");
238
- if (fromTime < currentTimeObj) {
239
- throw new app_badrequest_exception_1.AppBadRequestException({
240
- key: "slot.".concat(index),
241
- message: ["Booking time should be in future"],
242
- });
243
- }
258
+ BookingCode.previousTimeChecker = function (fromTime, fromDate, index, bookingDelayInMinutes, date) {
259
+ if (bookingDelayInMinutes === void 0) { bookingDelayInMinutes = _utils_1.DEFAULT_BOOKING_DELAY_IN_MINUTES; }
260
+ if (date === void 0) { date = date_util_1.dateUtilService.getIndianDate(); }
261
+ var now = date;
262
+ var bookingDate = date_util_1.dateUtilService.convertStringToDate(fromDate.toString() + fromTime, "yyMMddHHmm");
263
+ var difference = bookingDate.getTime() - now.getTime() + bookingDelayInMinutes * 60 * 1000;
264
+ if (difference < 0) {
265
+ throw new app_badrequest_exception_1.AppBadRequestException({
266
+ key: "slot.".concat(index),
267
+ message: ["Invalid booking time. Booking time should be within ".concat(bookingDelayInMinutes, " minutes from current time")],
268
+ });
244
269
  }
245
270
  };
246
271
  //---------------------
@@ -303,6 +328,11 @@ var BookingCode = /** @class */ (function () {
303
328
  .toString()
304
329
  .padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
305
330
  };
331
+ BookingCode.getMonthCode = function (date) {
332
+ return parseInt("".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
333
+ .toString()
334
+ .padStart(2, "0")));
335
+ };
306
336
  /**
307
337
  * Returns list of month codes (YYMM) in the Date range inclusive
308
338
  * @param {Date} from - Start Date
@@ -313,14 +343,18 @@ var BookingCode = /** @class */ (function () {
313
343
  from = new Date(from.getTime());
314
344
  to = new Date(to.getTime());
315
345
  var monthCodes = [];
316
- while (from < to) {
317
- var fromDateCode = BookingCode.getDateCode(from);
318
- monthCodes.push(parseInt("".concat(fromDateCode.slice(0, 4))));
319
- from.setMonth(from.getMonth() + 1);
320
- }
321
- var toDateCode = BookingCode.getDateCode(to);
322
- if (!monthCodes.includes(parseInt("".concat(toDateCode.slice(0, 4))))) {
323
- monthCodes.push(parseInt("".concat(toDateCode.slice(0, 4))));
346
+ var fromMonthCode = BookingCode.getMonthCode(from);
347
+ var toMonthCode = BookingCode.getMonthCode(to);
348
+ var currentMonthCode = fromMonthCode;
349
+ while (currentMonthCode <= toMonthCode) {
350
+ monthCodes.push(currentMonthCode);
351
+ // Change of year handling
352
+ if (currentMonthCode % 100 === 12) {
353
+ currentMonthCode = currentMonthCode + 100 - 11;
354
+ }
355
+ else {
356
+ currentMonthCode = currentMonthCode + 1;
357
+ }
324
358
  }
325
359
  return monthCodes;
326
360
  };
@@ -608,6 +642,15 @@ var BookingCode = /** @class */ (function () {
608
642
  this.pitchNumber === nextBookingCode.pitchNumber &&
609
643
  this.turfId === nextBookingCode.turfId);
610
644
  };
645
+ BookingCode.getInstanceByComponents = function (turfId, pitchCode, dateCode, fromTimeCode, toTimeCode, priceCsv) {
646
+ return new BookingCode("".concat(turfId.toString().padStart(4, "0")).concat(dateCode.toString().padStart(6, "0")).concat(fromTimeCode).concat(toTimeCode).concat(pitchCode.toString().padStart(2, "0")), priceCsv);
647
+ };
648
+ BookingCode.prototype.isTimeSlotContinuous = function (that) {
649
+ return this.toTimeCode == that.fromTimeCode &&
650
+ this.pitchNumber == that.pitchNumber &&
651
+ this.turfId == that.turfId &&
652
+ this.dateCode == that.dateCode;
653
+ };
611
654
  /**
612
655
  * Extracts the numeric part of a bookingCode, excluding a predefined deleted slot separator.
613
656
  *