turf-common 1.2.1-beta.1 → 1.2.1-beta.11
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 +1 -0
- package/build/@enum.js +1 -0
- package/build/enums/environment.enum.d.ts +5 -0
- package/build/enums/environment.enum.js +9 -0
- package/build/enums/valid-coupon-type.enum.d.ts +3 -1
- package/build/enums/valid-coupon-type.enum.js +2 -0
- package/build/interface/ui/booking-data.interface.d.ts +4 -2
- package/build/models/booking-code-model.d.ts +1 -1
- package/build/models/booking-code-model.js +22 -3
- package/build/models/charge-model.d.ts +2 -9
- package/build/models/charge-model.js +51 -70
- package/build/utils/string-utils.d.ts +1 -0
- package/build/utils/string-utils.js +31 -0
- package/package.json +1 -1
- package/build/utils/format-string-with-hyphens.d.ts +0 -1
- package/build/utils/format-string-with-hyphens.js +0 -7
package/build/@enum.d.ts
CHANGED
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,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 = {}));
|
|
@@ -5,4 +5,6 @@ var ValidCouponType;
|
|
|
5
5
|
(function (ValidCouponType) {
|
|
6
6
|
ValidCouponType["PERCENTAGE"] = "percentage";
|
|
7
7
|
ValidCouponType["UNIT"] = "unit";
|
|
8
|
+
ValidCouponType["PER_HOUR_UNIT"] = "per hour unit";
|
|
9
|
+
ValidCouponType["PER_HOUR_PERCENTAGE"] = "per hour percentage";
|
|
8
10
|
})(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { IBookingDetailsWithBookingCodes } from "../../@type";
|
|
1
|
+
import { IBookingDetailsWithBookingCodes, IChargeModel } from "../../@type";
|
|
2
2
|
import { IModifyEntity } from "../modify-entity.interface";
|
|
3
|
-
export interface
|
|
3
|
+
export interface IBookingDetailsData extends IModifyEntity<IBookingDetailsWithBookingCodes>, IChargeModel {
|
|
4
|
+
code?: string;
|
|
5
|
+
slot_cost?: string;
|
|
4
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;
|
|
@@ -116,12 +116,20 @@ var BookingCode = /** @class */ (function () {
|
|
|
116
116
|
var code = turfId + bookingDate + fhfm + thtm + pitchCode;
|
|
117
117
|
return code;
|
|
118
118
|
};
|
|
119
|
-
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply) {
|
|
119
|
+
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply, totalBookingHours) {
|
|
120
120
|
if (validationApply === void 0) { validationApply = true; }
|
|
121
121
|
var discount = 0;
|
|
122
122
|
var discountedCost = 0;
|
|
123
123
|
if (couponCode) {
|
|
124
|
-
|
|
124
|
+
var code = couponCode.match(/[a-zA-Z]+/g);
|
|
125
|
+
var value = couponCode.match(/\d+/g);
|
|
126
|
+
if (validationApply && !code && !value) {
|
|
127
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
128
|
+
key: "couponCode",
|
|
129
|
+
message: ["Coupon with code ".concat(couponCode, " is wrong ")],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (code && (code[0] === "P" || code[0] === "PHP")) {
|
|
125
133
|
var percentDiscount = parseFloat(couponCode);
|
|
126
134
|
if (validationApply) {
|
|
127
135
|
if (percentDiscount > 90) {
|
|
@@ -133,9 +141,20 @@ var BookingCode = /** @class */ (function () {
|
|
|
133
141
|
}
|
|
134
142
|
discount = totalCost * (percentDiscount / 100);
|
|
135
143
|
}
|
|
136
|
-
else if (
|
|
144
|
+
else if (code && code[0] === "U") {
|
|
137
145
|
discount = parseFloat(couponCode);
|
|
138
146
|
}
|
|
147
|
+
else if (code && code[0] === "PHU") {
|
|
148
|
+
if (!totalBookingHours) {
|
|
149
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
150
|
+
key: "totalBookingHours",
|
|
151
|
+
message: [
|
|
152
|
+
"Total Booking Hours is mandatory to calculate per hour unit",
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
discount = parseFloat(couponCode) * totalBookingHours;
|
|
157
|
+
}
|
|
139
158
|
}
|
|
140
159
|
discountedCost = totalCost - discount;
|
|
141
160
|
return Math.round(discountedCost);
|
|
@@ -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;
|
|
@@ -19,7 +18,7 @@ export declare class ChargesModel implements IChargeModel {
|
|
|
19
18
|
getNetAmount(): number;
|
|
20
19
|
getDiscountAmount(): number;
|
|
21
20
|
getPayableRefundAmount(): number;
|
|
22
|
-
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
21
|
+
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
|
|
23
22
|
setValues(values?: Partial<ChargesModel>): ChargesModel;
|
|
24
23
|
modify(bookingModification: IBookingModification): ChargesModel | null;
|
|
25
24
|
private modifyExtend;
|
|
@@ -27,14 +26,8 @@ export declare class ChargesModel implements IChargeModel {
|
|
|
27
26
|
private modifyMove;
|
|
28
27
|
clone(): ChargesModel;
|
|
29
28
|
private modifyDelete;
|
|
30
|
-
static
|
|
31
|
-
static assignByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
29
|
+
static getInstance(chargeData: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
32
30
|
getTotalAmount(): number;
|
|
33
31
|
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
32
|
getTotalNetAmount(): number;
|
|
40
33
|
}
|
|
@@ -46,11 +46,19 @@ var ChargesModel = /** @class */ (function () {
|
|
|
46
46
|
// this.totalRefundAmount = this.totalRefundAmount - refundAmount;
|
|
47
47
|
// this.refundedAmount += refundAmount;
|
|
48
48
|
// }
|
|
49
|
-
ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply) {
|
|
49
|
+
ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply, totalBookingHours) {
|
|
50
50
|
if (validationApply === void 0) { validationApply = false; }
|
|
51
51
|
var discountAmount = 0;
|
|
52
52
|
if (couponCode) {
|
|
53
|
-
|
|
53
|
+
var code = couponCode.match(/[a-zA-Z]+/g);
|
|
54
|
+
var value = couponCode.match(/\d+/g);
|
|
55
|
+
if (validationApply && !code && !value) {
|
|
56
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
57
|
+
key: "couponCode",
|
|
58
|
+
message: ["Coupon with code ".concat(couponCode, " is wrong ")],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (code && (code[0] === "P" || code[0] === "PHP")) {
|
|
54
62
|
var percentDiscount = parseFloat(couponCode);
|
|
55
63
|
if (validationApply && percentDiscount > 90) {
|
|
56
64
|
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
@@ -60,9 +68,20 @@ var ChargesModel = /** @class */ (function () {
|
|
|
60
68
|
}
|
|
61
69
|
discountAmount = totalCost * (percentDiscount / 100);
|
|
62
70
|
}
|
|
63
|
-
else if (
|
|
71
|
+
else if (code && code[0] === "U") {
|
|
64
72
|
discountAmount = parseFloat(couponCode);
|
|
65
73
|
}
|
|
74
|
+
else if (code && code[0] === "PHU") {
|
|
75
|
+
if (!totalBookingHours) {
|
|
76
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
77
|
+
key: "totalBookingHours",
|
|
78
|
+
message: [
|
|
79
|
+
"Total Booking Hours is mandatory to calculate per hour unit",
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
discountAmount = parseFloat(couponCode) * totalBookingHours;
|
|
84
|
+
}
|
|
66
85
|
}
|
|
67
86
|
return Math.round(discountAmount);
|
|
68
87
|
};
|
|
@@ -185,32 +204,38 @@ var ChargesModel = /** @class */ (function () {
|
|
|
185
204
|
}
|
|
186
205
|
return newChargeModel;
|
|
187
206
|
};
|
|
188
|
-
ChargesModel.
|
|
207
|
+
ChargesModel.getInstance = function (chargeData, discountPolicy) {
|
|
189
208
|
if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
|
|
190
|
-
var chargesModel = new ChargesModel(
|
|
191
|
-
Object.assign(chargesModel,
|
|
209
|
+
var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, discountPolicy);
|
|
210
|
+
Object.assign(chargesModel, chargeData);
|
|
192
211
|
return chargesModel;
|
|
193
212
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
// static assignByInterface(
|
|
214
|
+
// chargeData: IChargeModel,
|
|
215
|
+
// discountPolicy: ModificationDiscountPolicy = ModificationDiscountPolicy.DISCOUNT_CONDITIONAL
|
|
216
|
+
// ): ChargesModel {
|
|
217
|
+
// const newChargeModel = new ChargesModel(
|
|
218
|
+
// chargeData.initialBookingGrossAmount,
|
|
219
|
+
// chargeData.amountPaid,
|
|
220
|
+
// chargeData.couponCode,
|
|
221
|
+
// discountPolicy
|
|
222
|
+
// );
|
|
223
|
+
// newChargeModel.additionalBookingGrossAmount =
|
|
224
|
+
// chargeData.additionalBookingGrossAmount;
|
|
225
|
+
// newChargeModel.initialBookingGrossAmount =
|
|
226
|
+
// chargeData.initialBookingGrossAmount;
|
|
227
|
+
// newChargeModel.cancelledBookingGrossAmount =
|
|
228
|
+
// chargeData.cancelledBookingGrossAmount;
|
|
229
|
+
// newChargeModel.refundPayable = chargeData.refundPayable;
|
|
230
|
+
// newChargeModel.totalRefundedAmount = chargeData.totalRefundedAmount;
|
|
231
|
+
// newChargeModel.amountPaid = chargeData.amountPaid;
|
|
232
|
+
// newChargeModel.totalCancellationCharges =
|
|
233
|
+
// chargeData.totalCancellationCharges;
|
|
234
|
+
// newChargeModel.netTotal = chargeData.netTotal;
|
|
235
|
+
// newChargeModel.couponCode = chargeData.couponCode;
|
|
236
|
+
// newChargeModel.amountPayable = chargeData.amountPayable;
|
|
237
|
+
// return newChargeModel;
|
|
238
|
+
// }
|
|
214
239
|
ChargesModel.prototype.getTotalAmount = function () {
|
|
215
240
|
return this.getNetAmount() + this.totalCancellationCharges;
|
|
216
241
|
};
|
|
@@ -222,50 +247,6 @@ var ChargesModel = /** @class */ (function () {
|
|
|
222
247
|
? "Paid"
|
|
223
248
|
: "Pending";
|
|
224
249
|
};
|
|
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
250
|
ChargesModel.prototype.getTotalNetAmount = function () {
|
|
270
251
|
return this.getNetAmount() + this.totalCancellationCharges;
|
|
271
252
|
};
|
|
@@ -24,6 +24,37 @@ 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
|
+
};
|
|
27
58
|
return StringUtil;
|
|
28
59
|
}());
|
|
29
60
|
exports.stringUtil = new StringUtil();
|
package/package.json
CHANGED
|
@@ -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;
|