turf-common 1.0.0 → 1.0.2
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/README.md +11 -0
- package/build/enums/modification-discount-policy.enum.d.ts +5 -0
- package/build/enums/modification-discount-policy.enum.js +9 -0
- package/build/exceptions/app-badrequest.exception.d.ts +5 -0
- package/build/exceptions/app-badrequest.exception.js +28 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +24 -0
- package/build/interface/get-booking-codes-per-thirty-min.interface.d.ts +4 -0
- package/build/interface/get-booking-codes-per-thirty-min.interface.js +2 -0
- package/build/models/booking-code-model.d.ts +72 -0
- package/build/models/booking-code-model.js +414 -0
- package/build/models/charge-model.d.ts +44 -0
- package/build/models/charge-model.js +227 -0
- package/build/models/time-slot-model.d.ts +18 -0
- package/build/models/time-slot-model.js +95 -0
- package/build/modules/app-badrequest-exception-module/app-badrequest-exception-model.d.ts +5 -0
- package/build/modules/app-badrequest-exception-module/app-badrequest-exception-model.js +28 -0
- package/build/modules/app-badrequest-exception-module/types/app-badrequest-exception.type.d.ts +4 -0
- package/build/modules/app-badrequest-exception-module/types/app-badrequest-exception.type.js +2 -0
- package/build/modules/booking-module/booking-code-model.d.ts +71 -0
- package/build/modules/booking-module/booking-code-model.js +407 -0
- package/build/modules/booking-module/interfaces/get-booking-codes-per-thirty-min.interface.d.ts +4 -0
- package/build/modules/booking-module/interfaces/get-booking-codes-per-thirty-min.interface.js +2 -0
- package/build/modules/charge-module/charge-model.d.ts +44 -0
- package/build/modules/charge-module/charge-model.js +227 -0
- package/build/modules/charge-module/enums/modification-discount-policy.enum.d.ts +5 -0
- package/build/modules/charge-module/enums/modification-discount-policy.enum.js +9 -0
- package/build/modules/charge-module/types/booking-modification.type.d.ts +6 -0
- package/build/modules/charge-module/types/booking-modification.type.js +2 -0
- package/build/modules/date-module/date-code-model.d.ts +8 -0
- package/build/modules/date-module/date-code-model.js +38 -0
- package/build/modules/time-slot-module/time-slot-model.d.ts +18 -0
- package/build/modules/time-slot-module/time-slot-model.js +95 -0
- package/build/types/app-badrequest-exception.type.d.ts +4 -0
- package/build/types/app-badrequest-exception.type.js +2 -0
- package/build/types/booking-modification.type.d.ts +6 -0
- package/build/types/booking-modification.type.js +2 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModificationDiscountPolicy = void 0;
|
|
4
|
+
var ModificationDiscountPolicy;
|
|
5
|
+
(function (ModificationDiscountPolicy) {
|
|
6
|
+
ModificationDiscountPolicy["DISCOUNT_RECALL"] = "discount_recall";
|
|
7
|
+
ModificationDiscountPolicy["DISCOUNT_RELATIVE"] = "discount_relative";
|
|
8
|
+
ModificationDiscountPolicy["DISCOUNT_CONDITIONAL"] = "discount_conditional";
|
|
9
|
+
})(ModificationDiscountPolicy || (exports.ModificationDiscountPolicy = ModificationDiscountPolicy = {}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AppBadRequestException = void 0;
|
|
19
|
+
var AppBadRequestException = /** @class */ (function (_super) {
|
|
20
|
+
__extends(AppBadRequestException, _super);
|
|
21
|
+
function AppBadRequestException(appBadRequestException) {
|
|
22
|
+
var _this = _super.call(this) || this;
|
|
23
|
+
_this.appBadRequestException = appBadRequestException;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return AppBadRequestException;
|
|
27
|
+
}(Error));
|
|
28
|
+
exports.AppBadRequestException = AppBadRequestException;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./models/booking-code-model";
|
|
2
|
+
export * from "./models/charge-model";
|
|
3
|
+
export * from "./models/time-slot-model";
|
|
4
|
+
export * from "./exceptions/app-badrequest.exception";
|
|
5
|
+
export * from "./types/app-badrequest-exception.type";
|
|
6
|
+
export * from "./types/booking-modification.type";
|
|
7
|
+
export * from "./interface/get-booking-codes-per-thirty-min.interface";
|
|
8
|
+
export * from "./enums/modification-discount-policy.enum";
|
package/build/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./models/booking-code-model"), exports);
|
|
18
|
+
__exportStar(require("./models/charge-model"), exports);
|
|
19
|
+
__exportStar(require("./models/time-slot-model"), exports);
|
|
20
|
+
__exportStar(require("./exceptions/app-badrequest.exception"), exports);
|
|
21
|
+
__exportStar(require("./types/app-badrequest-exception.type"), exports);
|
|
22
|
+
__exportStar(require("./types/booking-modification.type"), exports);
|
|
23
|
+
__exportStar(require("./interface/get-booking-codes-per-thirty-min.interface"), exports);
|
|
24
|
+
__exportStar(require("./enums/modification-discount-policy.enum"), exports);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TimeSlot } from "./time-slot-model";
|
|
2
|
+
import { IGetBookingCodesPerThirtyMinutes } from "../interface/get-booking-codes-per-thirty-min.interface";
|
|
3
|
+
export declare class BookingCode {
|
|
4
|
+
code: string;
|
|
5
|
+
turfid: string;
|
|
6
|
+
pitchCode: string;
|
|
7
|
+
slot: string;
|
|
8
|
+
fromTime: string;
|
|
9
|
+
toTime: string;
|
|
10
|
+
date: string;
|
|
11
|
+
cost: string;
|
|
12
|
+
constructor(code: string, cost?: string);
|
|
13
|
+
parse(): BookingCode;
|
|
14
|
+
getBookingTimeInMinutes(): number;
|
|
15
|
+
getPitchNo(): number;
|
|
16
|
+
getHalfHourTimeCodes(): string[];
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
|
|
20
|
+
* @example fromTime: 0000; toTime: 0130
|
|
21
|
+
* // returns ['00000030','00300100','01000130']
|
|
22
|
+
*/
|
|
23
|
+
getHalfHourTimeRangeCodes(): string[];
|
|
24
|
+
getValidDate(): Date;
|
|
25
|
+
getDateCode(): string;
|
|
26
|
+
getWeekday(): number;
|
|
27
|
+
getMonthCode(): string;
|
|
28
|
+
getDateWithFromTimeCode(): string;
|
|
29
|
+
getCodeWithoutTurfCode(): string;
|
|
30
|
+
static sortByCode(bookingCodes: BookingCode[]): void;
|
|
31
|
+
static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
|
|
32
|
+
static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
33
|
+
static getDiscountAmount(couponCode: string, totalCost: number): number;
|
|
34
|
+
static isValidDate(date: string): boolean;
|
|
35
|
+
static parseDateCode(dateCode: string): Date;
|
|
36
|
+
static getWeekday(dateCode: number): number;
|
|
37
|
+
static convertToDate(str: string): Date;
|
|
38
|
+
static previousDateChecker(fromDate: number, index: number, errorKey?: string): void;
|
|
39
|
+
static previousTimeChecker(fromTime: string, fromDate: number, index: number): void;
|
|
40
|
+
static getDateCodesByWeek(fromDate: number, toDate: number, selectedWeekday: number): string[];
|
|
41
|
+
static getDatesByWeek(fromDate: number, toDate: number, selectedWeekday: number): Date[];
|
|
42
|
+
static isValidTimeRange(timeSlot: string): boolean;
|
|
43
|
+
static dateFormat(dates: Array<Date>): Array<string>;
|
|
44
|
+
static getDateCode(date: Date): string;
|
|
45
|
+
/**
|
|
46
|
+
* Returns list of month codes (YYMM) in the Date range inclusive
|
|
47
|
+
* @param {Date} from - Start Date
|
|
48
|
+
* @param {Date} to - End Date
|
|
49
|
+
* @return {Array<Number>} - The array of month codes (YYMM)
|
|
50
|
+
*/
|
|
51
|
+
static getMonthCodesRange(from: Date, to: Date): number[];
|
|
52
|
+
static getNMonthCodes(n: number): number[];
|
|
53
|
+
static getCodes(fromDate: number, toDate: number, weekday: number, turfId: number, from: string, to: string): string[];
|
|
54
|
+
static getNextDayDateCode(dateCode: number): number;
|
|
55
|
+
getUtcDateWithTime(dateCodeWithTime: string): Date;
|
|
56
|
+
static getUtcDateWithTime(dateCodeWithTime: string): Date;
|
|
57
|
+
getNoOfHoursDifference(): number;
|
|
58
|
+
static getBookingCodesPerThirtyMinutes(from: string, to: string, bookingDate: string): IGetBookingCodesPerThirtyMinutes[];
|
|
59
|
+
static getCostPerThirtyMinutes(bookingCodePerThirtyMinutesPerSlot: {
|
|
60
|
+
slotCodePerThirtyMinute: string;
|
|
61
|
+
bookingDate: string;
|
|
62
|
+
}[], pricePerThirtyMinutesData: {
|
|
63
|
+
[date: string]: {
|
|
64
|
+
[time: string]: number;
|
|
65
|
+
};
|
|
66
|
+
}): string;
|
|
67
|
+
static padBookingCode(bookingCodeWithoutTurfCode: string): string;
|
|
68
|
+
static getInstance(turfId: number, bookingCodeWithoutTurfCode: string): BookingCode;
|
|
69
|
+
getCost(): number;
|
|
70
|
+
getTimeslot(): TimeSlot;
|
|
71
|
+
static getIndianTimeZoneDate(bookingBufferOffsetHour?: number): Date;
|
|
72
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.BookingCode = void 0;
|
|
15
|
+
var time_slot_model_1 = require("./time-slot-model");
|
|
16
|
+
var charge_model_1 = require("./charge-model");
|
|
17
|
+
var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
|
|
18
|
+
var BookingCode = /** @class */ (function () {
|
|
19
|
+
function BookingCode(code, cost) {
|
|
20
|
+
if (cost === void 0) { cost = "-1"; }
|
|
21
|
+
// this.id = turfid;
|
|
22
|
+
if (code.length === 18)
|
|
23
|
+
this.code = code + "00";
|
|
24
|
+
else
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.cost = cost;
|
|
27
|
+
this.parse();
|
|
28
|
+
}
|
|
29
|
+
BookingCode.prototype.parse = function () {
|
|
30
|
+
var regexp = /(\d{4})(\d{6})(\d{8})(\d{2})/g;
|
|
31
|
+
var matches = regexp.exec(this.code);
|
|
32
|
+
if (!matches) {
|
|
33
|
+
throw new Error("Booking slot ".concat(this.code, " is invalid"));
|
|
34
|
+
}
|
|
35
|
+
this.turfid = matches[1];
|
|
36
|
+
this.date = matches[2];
|
|
37
|
+
this.slot = matches[3];
|
|
38
|
+
this.fromTime = matches[3].slice(0, 4);
|
|
39
|
+
this.toTime = matches[3].slice(4, 8);
|
|
40
|
+
this.pitchCode = matches[4];
|
|
41
|
+
return this;
|
|
42
|
+
};
|
|
43
|
+
BookingCode.prototype.getBookingTimeInMinutes = function () {
|
|
44
|
+
//from HHMM to HHMM
|
|
45
|
+
var fromHours = parseInt(this.fromTime.slice(0, 2));
|
|
46
|
+
var fromMinutes = parseInt(this.fromTime.slice(2, 4));
|
|
47
|
+
var toHours = parseInt(this.toTime.slice(0, 2));
|
|
48
|
+
var toMinutes = parseInt(this.toTime.slice(2, 4));
|
|
49
|
+
return toHours * 60 + toMinutes - (fromHours * 60 + fromMinutes);
|
|
50
|
+
};
|
|
51
|
+
BookingCode.prototype.getPitchNo = function () {
|
|
52
|
+
return parseInt(this.pitchCode);
|
|
53
|
+
};
|
|
54
|
+
BookingCode.prototype.getHalfHourTimeCodes = function () {
|
|
55
|
+
return new time_slot_model_1.TimeSlot(this.fromTime, this.toTime).getHalfHourTimeCodes();
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
|
|
60
|
+
* @example fromTime: 0000; toTime: 0130
|
|
61
|
+
* // returns ['00000030','00300100','01000130']
|
|
62
|
+
*/
|
|
63
|
+
BookingCode.prototype.getHalfHourTimeRangeCodes = function () {
|
|
64
|
+
var halfHourCodes = this.getHalfHourTimeCodes();
|
|
65
|
+
var halfHourRangeCodes = [];
|
|
66
|
+
for (var index = 0; index < halfHourCodes.length - 1; index++) {
|
|
67
|
+
halfHourRangeCodes.push(halfHourCodes[index] + halfHourCodes[index + 1]);
|
|
68
|
+
}
|
|
69
|
+
return halfHourRangeCodes;
|
|
70
|
+
};
|
|
71
|
+
BookingCode.prototype.getValidDate = function () {
|
|
72
|
+
// Date format: YYMMDD
|
|
73
|
+
function getDate(dateString) {
|
|
74
|
+
var separators = ["\\.", "\\-", "\\/"];
|
|
75
|
+
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
76
|
+
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
77
|
+
return new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
78
|
+
}
|
|
79
|
+
return getDate("20".concat(this.date.slice(0, 2), ".").concat(this.date.slice(2, 4), ".").concat(this.date.slice(4, 6)));
|
|
80
|
+
};
|
|
81
|
+
BookingCode.prototype.getDateCode = function () {
|
|
82
|
+
var date = this.getValidDate();
|
|
83
|
+
return "".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
|
|
84
|
+
.toString()
|
|
85
|
+
.padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
|
|
86
|
+
};
|
|
87
|
+
BookingCode.prototype.getWeekday = function () {
|
|
88
|
+
var dateObj = new Date(2000 + parseInt(this.date.slice(0, 2)), // Year
|
|
89
|
+
parseInt(this.date.toString().slice(2, 4)) - 1, // Month (0-indexed)
|
|
90
|
+
parseInt(this.date.toString().slice(4, 6)) // Day
|
|
91
|
+
);
|
|
92
|
+
return dateObj.getDay() === 0 ? 7 : dateObj.getDay();
|
|
93
|
+
// return weekday;
|
|
94
|
+
};
|
|
95
|
+
BookingCode.prototype.getMonthCode = function () {
|
|
96
|
+
return this.date.slice(0, 4);
|
|
97
|
+
};
|
|
98
|
+
BookingCode.prototype.getDateWithFromTimeCode = function () {
|
|
99
|
+
return "".concat(this.date).concat(this.fromTime);
|
|
100
|
+
};
|
|
101
|
+
BookingCode.prototype.getCodeWithoutTurfCode = function () {
|
|
102
|
+
return "".concat(this.date).concat(this.slot).concat(this.pitchCode);
|
|
103
|
+
};
|
|
104
|
+
BookingCode.sortByCode = function (bookingCodes) {
|
|
105
|
+
bookingCodes.sort(function (_a, _b) {
|
|
106
|
+
var code1 = _a.code;
|
|
107
|
+
var code2 = _b.code;
|
|
108
|
+
return code1 < code2 ? -1 : code1 > code2 ? 1 : 0;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
// code: TTTTYYMMDDFHFMTHTMPP;
|
|
112
|
+
BookingCode.getOneSlotBookingCode = function (turfId, bookingDate, fhfm, thtm, pitchCode) {
|
|
113
|
+
var code = turfId + bookingDate + fhfm + thtm + pitchCode;
|
|
114
|
+
return code;
|
|
115
|
+
};
|
|
116
|
+
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply) {
|
|
117
|
+
if (validationApply === void 0) { validationApply = true; }
|
|
118
|
+
var discount = 0;
|
|
119
|
+
var discountedCost = 0;
|
|
120
|
+
if (couponCode) {
|
|
121
|
+
if (couponCode.endsWith("P")) {
|
|
122
|
+
var percentDiscount = parseFloat(couponCode);
|
|
123
|
+
if (validationApply) {
|
|
124
|
+
if (percentDiscount > 90) {
|
|
125
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
126
|
+
key: "couponCode",
|
|
127
|
+
message: ["Discount should not be more than 90P"],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
discount = totalCost * (percentDiscount / 100);
|
|
132
|
+
}
|
|
133
|
+
else if (couponCode.endsWith("U")) {
|
|
134
|
+
discount = parseFloat(couponCode);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
discountedCost = totalCost - discount;
|
|
138
|
+
return Math.round(discountedCost);
|
|
139
|
+
};
|
|
140
|
+
BookingCode.getDiscountAmount = function (couponCode, totalCost) {
|
|
141
|
+
return charge_model_1.ChargesModel.getDiscountAmount(couponCode, totalCost, true);
|
|
142
|
+
};
|
|
143
|
+
//-----------------
|
|
144
|
+
BookingCode.isValidDate = function (date) {
|
|
145
|
+
// Date format: YYMMDD
|
|
146
|
+
function isDate(dateString) {
|
|
147
|
+
var separators = ["\\.", "\\-", "\\/"];
|
|
148
|
+
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
149
|
+
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
150
|
+
var parsedDate = new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
151
|
+
return (parsedDate.getFullYear() === intBits[0] &&
|
|
152
|
+
parsedDate.getMonth() + 1 === intBits[1] &&
|
|
153
|
+
parsedDate.getDate() === intBits[2]);
|
|
154
|
+
}
|
|
155
|
+
return isDate("20".concat(date.slice(0, 2), ".").concat(date.slice(2, 4), ".").concat(date.slice(4, 6)));
|
|
156
|
+
};
|
|
157
|
+
BookingCode.parseDateCode = function (dateCode) {
|
|
158
|
+
// Date format: YYMMDD
|
|
159
|
+
function getDate(dateString) {
|
|
160
|
+
var separators = ["\\.", "\\-", "\\/"];
|
|
161
|
+
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
162
|
+
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
163
|
+
return new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
164
|
+
}
|
|
165
|
+
return getDate("20".concat(dateCode.slice(0, 2), ".").concat(dateCode.slice(2, 4), ".").concat(dateCode.slice(4, 6)));
|
|
166
|
+
};
|
|
167
|
+
//------------------
|
|
168
|
+
BookingCode.getWeekday = function (dateCode) {
|
|
169
|
+
var dateObj = new Date(2000 + parseInt(dateCode.toString().slice(0, 2)), // Year
|
|
170
|
+
parseInt(dateCode.toString().slice(2, 4)) - 1, // Month (0-indexed)
|
|
171
|
+
parseInt(dateCode.toString().slice(4, 6)) // Day
|
|
172
|
+
);
|
|
173
|
+
var weekday = dateObj.getDay();
|
|
174
|
+
return weekday === 0 ? 7 : weekday;
|
|
175
|
+
};
|
|
176
|
+
//---------------------
|
|
177
|
+
BookingCode.convertToDate = function (str) {
|
|
178
|
+
var year = parseInt(20 + str.slice(0, 2));
|
|
179
|
+
var month = parseInt(str.slice(2, 4)) - 1;
|
|
180
|
+
var day = parseInt(str.slice(4, 6));
|
|
181
|
+
var date = new Date(Date.UTC(year, month, day, 0, 0, 0));
|
|
182
|
+
return date;
|
|
183
|
+
};
|
|
184
|
+
//---------------------
|
|
185
|
+
BookingCode.previousDateChecker = function (fromDate, index, errorKey) {
|
|
186
|
+
var slotDate = this.convertToDate(fromDate.toString());
|
|
187
|
+
var currentDateObj = new Date();
|
|
188
|
+
var parsedDate = this.dateFormat([slotDate]);
|
|
189
|
+
var currentDate = this.dateFormat([currentDateObj]);
|
|
190
|
+
if (parsedDate < currentDate) {
|
|
191
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
192
|
+
key: errorKey !== null && errorKey !== void 0 ? errorKey : "slot.".concat(index),
|
|
193
|
+
message: ["date must be present Date or future Date"],
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else if (parsedDate === currentDate) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
//---------------------
|
|
201
|
+
BookingCode.previousTimeChecker = function (fromTime, fromDate, index) {
|
|
202
|
+
var now = new Date();
|
|
203
|
+
this.convertToDate(fromDate.toString());
|
|
204
|
+
var delayInBooking = 15;
|
|
205
|
+
if (this.convertToDate(fromDate.toString()) > now) {
|
|
206
|
+
return; //do nothing if fromDate is in future
|
|
207
|
+
}
|
|
208
|
+
else if (this.convertToDate(fromDate.toString()) <= now) {
|
|
209
|
+
now.setMinutes(now.getMinutes() - delayInBooking); // 15minutes buffer for late bookings
|
|
210
|
+
var options = {
|
|
211
|
+
timeZone: "Asia/Kolkata",
|
|
212
|
+
};
|
|
213
|
+
var timeFormat = new Intl.DateTimeFormat("en-US", __assign(__assign({}, options), { hour: "2-digit", minute: "2-digit", hour12: false }));
|
|
214
|
+
var currentTimeObj = timeFormat.format(now).replace(/:/g, "");
|
|
215
|
+
if (fromTime < currentTimeObj) {
|
|
216
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
217
|
+
key: "slot.".concat(index),
|
|
218
|
+
message: ["Booking time should be in future"],
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
//---------------------
|
|
224
|
+
BookingCode.getDateCodesByWeek = function (fromDate, toDate, selectedWeekday) {
|
|
225
|
+
return BookingCode.dateFormat(BookingCode.getDatesByWeek(fromDate, toDate, selectedWeekday));
|
|
226
|
+
};
|
|
227
|
+
BookingCode.getDatesByWeek = function (fromDate, toDate, selectedWeekday) {
|
|
228
|
+
if (!BookingCode.isValidDate(fromDate.toString()) ||
|
|
229
|
+
!BookingCode.isValidDate(toDate.toString())) {
|
|
230
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
231
|
+
key: "Date",
|
|
232
|
+
message: ["Invalid Date"],
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (selectedWeekday < 0 || selectedWeekday > 7) {
|
|
236
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
237
|
+
key: "weekday",
|
|
238
|
+
message: ["weekday should be between 1-7"],
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
var startDate = BookingCode.convertToDate(fromDate.toString());
|
|
242
|
+
var endDate = BookingCode.convertToDate(toDate.toString());
|
|
243
|
+
var currentDate = startDate;
|
|
244
|
+
var dates = [];
|
|
245
|
+
while (currentDate <= endDate) {
|
|
246
|
+
var weekday = currentDate.getDay();
|
|
247
|
+
if (weekday === selectedWeekday % 7) {
|
|
248
|
+
dates.push(new Date(currentDate.getTime()));
|
|
249
|
+
currentDate.setDate(currentDate.getDate() + 7);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
currentDate.setDate(currentDate.getDate() + 1);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return dates;
|
|
256
|
+
};
|
|
257
|
+
//--------------------
|
|
258
|
+
BookingCode.isValidTimeRange = function (timeSlot) {
|
|
259
|
+
var timeformat = /^(([01]\d|2[0-3])([0-5]\d|60)|2400|0000)$/;
|
|
260
|
+
var isValidTime = timeformat.test(timeSlot) && parseInt(timeSlot, 10) <= 2400;
|
|
261
|
+
return isValidTime;
|
|
262
|
+
};
|
|
263
|
+
//---------------------
|
|
264
|
+
BookingCode.dateFormat = function (dates) {
|
|
265
|
+
var codes = [];
|
|
266
|
+
for (var _i = 0, dates_1 = dates; _i < dates_1.length; _i++) {
|
|
267
|
+
var date = dates_1[_i];
|
|
268
|
+
var dateYear = date.getFullYear() % 2000;
|
|
269
|
+
var dateMonth = date.getMonth() + 1;
|
|
270
|
+
var dateDay = date.getDate();
|
|
271
|
+
var dateFormat = dateYear.toString() +
|
|
272
|
+
dateMonth.toString().padStart(2, "0") +
|
|
273
|
+
dateDay.toString().padStart(2, "0");
|
|
274
|
+
codes.push(dateFormat);
|
|
275
|
+
}
|
|
276
|
+
return codes;
|
|
277
|
+
};
|
|
278
|
+
BookingCode.getDateCode = function (date) {
|
|
279
|
+
return "".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
|
|
280
|
+
.toString()
|
|
281
|
+
.padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Returns list of month codes (YYMM) in the Date range inclusive
|
|
285
|
+
* @param {Date} from - Start Date
|
|
286
|
+
* @param {Date} to - End Date
|
|
287
|
+
* @return {Array<Number>} - The array of month codes (YYMM)
|
|
288
|
+
*/
|
|
289
|
+
BookingCode.getMonthCodesRange = function (from, to) {
|
|
290
|
+
from = new Date(from.getTime());
|
|
291
|
+
to = new Date(to.getTime());
|
|
292
|
+
var monthCodes = [];
|
|
293
|
+
while (from < to) {
|
|
294
|
+
var fromDateCode = BookingCode.getDateCode(from);
|
|
295
|
+
monthCodes.push(parseInt("".concat(fromDateCode.slice(0, 4))));
|
|
296
|
+
from.setMonth(from.getMonth() + 1);
|
|
297
|
+
}
|
|
298
|
+
var toDateCode = BookingCode.getDateCode(to);
|
|
299
|
+
if (!monthCodes.includes(parseInt("".concat(toDateCode.slice(0, 4))))) {
|
|
300
|
+
monthCodes.push(parseInt("".concat(toDateCode.slice(0, 4))));
|
|
301
|
+
}
|
|
302
|
+
return monthCodes;
|
|
303
|
+
};
|
|
304
|
+
BookingCode.getNMonthCodes = function (n) {
|
|
305
|
+
var now = new Date();
|
|
306
|
+
var future = new Date(now.getTime());
|
|
307
|
+
future.setMonth(now.getMonth() + n);
|
|
308
|
+
return BookingCode.getMonthCodesRange(now, future);
|
|
309
|
+
};
|
|
310
|
+
BookingCode.getCodes = function (fromDate, toDate, weekday, turfId, from, to) {
|
|
311
|
+
// const {fromDate, toDate, weekday, turfId, from, to} = bookingSlot
|
|
312
|
+
var dates = this.getDateCodesByWeek(fromDate, toDate, weekday);
|
|
313
|
+
// TTTTYYMMDDFFFFTTTT
|
|
314
|
+
var codes = [];
|
|
315
|
+
for (var _i = 0, dates_2 = dates; _i < dates_2.length; _i++) {
|
|
316
|
+
var date = dates_2[_i];
|
|
317
|
+
codes.push("".concat(turfId.toString().padStart(4, "0")).concat(date).concat(from).concat(to));
|
|
318
|
+
}
|
|
319
|
+
return codes;
|
|
320
|
+
};
|
|
321
|
+
//To check fromDate and toDate present in weekDays and return dateCode
|
|
322
|
+
BookingCode.getNextDayDateCode = function (dateCode) {
|
|
323
|
+
var nextDate = BookingCode.parseDateCode(dateCode.toString());
|
|
324
|
+
nextDate.setDate(nextDate.getDate() + 1);
|
|
325
|
+
return parseInt(BookingCode.getDateCode(nextDate));
|
|
326
|
+
};
|
|
327
|
+
BookingCode.prototype.getUtcDateWithTime = function (dateCodeWithTime) {
|
|
328
|
+
// const dateCodeWithTime = '2305131200';
|
|
329
|
+
var year = parseInt(dateCodeWithTime.slice(0, 2)) + 2000;
|
|
330
|
+
var month = parseInt(dateCodeWithTime.slice(2, 4)) - 1;
|
|
331
|
+
var day = parseInt(dateCodeWithTime.slice(4, 6));
|
|
332
|
+
var hours = parseInt(dateCodeWithTime.slice(6, 8));
|
|
333
|
+
var minutes = parseInt(dateCodeWithTime.slice(8, 10));
|
|
334
|
+
return new Date(Date.UTC(year, month, day, hours, minutes));
|
|
335
|
+
};
|
|
336
|
+
BookingCode.getUtcDateWithTime = function (dateCodeWithTime) {
|
|
337
|
+
// const dateCodeWithTime = '2305131200';
|
|
338
|
+
var year = parseInt(dateCodeWithTime.slice(0, 2)) + 2000;
|
|
339
|
+
var month = parseInt(dateCodeWithTime.slice(2, 4)) - 1;
|
|
340
|
+
var day = parseInt(dateCodeWithTime.slice(4, 6));
|
|
341
|
+
var hours = parseInt(dateCodeWithTime.slice(6, 8));
|
|
342
|
+
var minutes = parseInt(dateCodeWithTime.slice(8, 10));
|
|
343
|
+
return new Date(Date.UTC(year, month, day, hours, minutes));
|
|
344
|
+
};
|
|
345
|
+
BookingCode.prototype.getNoOfHoursDifference = function () {
|
|
346
|
+
var bookingDate = BookingCode.getUtcDateWithTime(this.getDateWithFromTimeCode());
|
|
347
|
+
var date = BookingCode.getIndianTimeZoneDate();
|
|
348
|
+
var timeDifferenceMs = bookingDate.getTime() - date.getTime();
|
|
349
|
+
return timeDifferenceMs / (1000 * 60 * 60);
|
|
350
|
+
};
|
|
351
|
+
BookingCode.getBookingCodesPerThirtyMinutes = function (from, to, bookingDate) {
|
|
352
|
+
var bookingCodePerThirtyMinutes = [];
|
|
353
|
+
while (from < to) {
|
|
354
|
+
var lastDigit = from.slice(2, 4);
|
|
355
|
+
if (lastDigit == "00") {
|
|
356
|
+
var code = "".concat(from).concat((Number(from) + 30)
|
|
357
|
+
.toString()
|
|
358
|
+
.padStart(4, "0"));
|
|
359
|
+
bookingCodePerThirtyMinutes.push({
|
|
360
|
+
slotCodePerThirtyMinute: code,
|
|
361
|
+
bookingDate: bookingDate,
|
|
362
|
+
});
|
|
363
|
+
from = (Number(from) + 30).toString().padStart(4, "0");
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
var code = "".concat(from).concat((Number(from) + 70)
|
|
367
|
+
.toString()
|
|
368
|
+
.padStart(4, "0"));
|
|
369
|
+
bookingCodePerThirtyMinutes.push({
|
|
370
|
+
slotCodePerThirtyMinute: code,
|
|
371
|
+
bookingDate: bookingDate,
|
|
372
|
+
});
|
|
373
|
+
from = (Number(from) + 70).toString().padStart(4, "0");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return bookingCodePerThirtyMinutes;
|
|
377
|
+
};
|
|
378
|
+
BookingCode.getCostPerThirtyMinutes = function (bookingCodePerThirtyMinutesPerSlot, pricePerThirtyMinutesData) {
|
|
379
|
+
var cost = [];
|
|
380
|
+
bookingCodePerThirtyMinutesPerSlot.forEach(function (slot) {
|
|
381
|
+
var weekDay = BookingCode.getWeekday(Number(slot.bookingDate));
|
|
382
|
+
var month = slot.bookingDate.slice(0, 4);
|
|
383
|
+
var monthWeekday = "".concat(month).concat(weekDay);
|
|
384
|
+
var price = pricePerThirtyMinutesData[monthWeekday][slot.slotCodePerThirtyMinute];
|
|
385
|
+
cost.push(price.toString());
|
|
386
|
+
});
|
|
387
|
+
return cost.join(",");
|
|
388
|
+
};
|
|
389
|
+
BookingCode.padBookingCode = function (bookingCodeWithoutTurfCode) {
|
|
390
|
+
return bookingCodeWithoutTurfCode.padStart(20, "0");
|
|
391
|
+
};
|
|
392
|
+
BookingCode.getInstance = function (turfId, bookingCodeWithoutTurfCode) {
|
|
393
|
+
return new BookingCode("".concat(turfId.toString().padStart(4, "0")).concat(bookingCodeWithoutTurfCode));
|
|
394
|
+
};
|
|
395
|
+
BookingCode.prototype.getCost = function () {
|
|
396
|
+
return this.cost
|
|
397
|
+
.split(",")
|
|
398
|
+
.map(function (a) { return parseInt(a); })
|
|
399
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
400
|
+
};
|
|
401
|
+
BookingCode.prototype.getTimeslot = function () {
|
|
402
|
+
return new time_slot_model_1.TimeSlot(this.fromTime, this.toTime);
|
|
403
|
+
};
|
|
404
|
+
BookingCode.getIndianTimeZoneDate = function (bookingBufferOffsetHour) {
|
|
405
|
+
var now = new Date();
|
|
406
|
+
var utcOffsetMinutes = 330; // Indian Standard Time (IST) offset is UTC+05:30
|
|
407
|
+
var indianTimeMillis = now.getTime() +
|
|
408
|
+
utcOffsetMinutes * 60 * 1000 +
|
|
409
|
+
(bookingBufferOffsetHour || 0) * 60 * 60 * 1000;
|
|
410
|
+
return new Date(indianTimeMillis);
|
|
411
|
+
};
|
|
412
|
+
return BookingCode;
|
|
413
|
+
}());
|
|
414
|
+
exports.BookingCode = BookingCode;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IBookingModification } from "../types/booking-modification.type";
|
|
2
|
+
import { ModificationDiscountPolicy } from "../enums/modification-discount-policy.enum";
|
|
3
|
+
export interface IChargeModel {
|
|
4
|
+
initialBookingGrossAmount: number;
|
|
5
|
+
additionalBookingGrossAmount: number;
|
|
6
|
+
cancelledBookingGrossAmount: number;
|
|
7
|
+
totalCancellationCharges: number;
|
|
8
|
+
refundPayable: number;
|
|
9
|
+
netTotal: number;
|
|
10
|
+
amountPaid: number;
|
|
11
|
+
amountPayable: number;
|
|
12
|
+
totalRefundedAmount: number;
|
|
13
|
+
couponCode: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class ChargesModel implements IChargeModel {
|
|
16
|
+
initialBookingGrossAmount: number;
|
|
17
|
+
additionalBookingGrossAmount: number;
|
|
18
|
+
cancelledBookingGrossAmount: number;
|
|
19
|
+
totalCancellationCharges: number;
|
|
20
|
+
refundPayable: number;
|
|
21
|
+
netTotal: number;
|
|
22
|
+
amountPaid: number;
|
|
23
|
+
amountPayable: number;
|
|
24
|
+
totalRefundedAmount: number;
|
|
25
|
+
couponCode: string;
|
|
26
|
+
discountPolicy: ModificationDiscountPolicy;
|
|
27
|
+
constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, discountPolicy: ModificationDiscountPolicy);
|
|
28
|
+
getGrossAmount(): number;
|
|
29
|
+
getNetAmount(): number;
|
|
30
|
+
getDiscountAmount(): number;
|
|
31
|
+
getPayableRefundAmount(): number;
|
|
32
|
+
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
33
|
+
setValues(values?: Partial<ChargesModel>): ChargesModel;
|
|
34
|
+
modify(bookingModification: IBookingModification): ChargesModel | null;
|
|
35
|
+
private modifyExtend;
|
|
36
|
+
private modifyReduce;
|
|
37
|
+
private modifyMove;
|
|
38
|
+
clone(): ChargesModel;
|
|
39
|
+
private modifyDelete;
|
|
40
|
+
static getInstanceByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
41
|
+
static assignByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
42
|
+
getTotalAmount(): number;
|
|
43
|
+
getPaymentStatus(): "Refund" | "Paid" | "Pending";
|
|
44
|
+
}
|