turf-common 1.1.1-beta.52 → 1.1.1-beta.53

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.
@@ -32,4 +32,6 @@ export declare class SubscribedPricingPlanModel extends PricingPlanModel {
32
32
  getNextBillingCycleDateRange(date: Date): [Date, Date];
33
33
  static getInstanceBySubscriptionData(data: IGetPricingPlanByDateResponse, subscriptionDataModel: SubscriptionModel): SubscribedPricingPlanModel;
34
34
  getSelectedPitchSlabBasePrice(): number;
35
+ getBasePriceBySelectedBillingCycleDiscount(): number;
36
+ getTotalHours(): number;
35
37
  }
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SubscribedPricingPlanModel = void 0;
19
19
  var date_util_1 = require("../utils/date-util");
20
+ var math_util_1 = require("../utils/math-util");
20
21
  var pricing_plan_model_1 = require("./pricing-plan-model");
21
22
  var SubscribedPricingPlanModel = /** @class */ (function (_super) {
22
23
  __extends(SubscribedPricingPlanModel, _super);
@@ -42,14 +43,12 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
42
43
  if (!roundDown) {
43
44
  return Math.round(this.selectedPitchSlabBasePrice *
44
45
  this.pitchCount *
45
- this.hourInMonth *
46
- this.selectedBillingCycle.to);
46
+ this.getTotalHours());
47
47
  }
48
48
  else {
49
49
  return Math.floor(this.selectedPitchSlabBasePrice *
50
50
  this.pitchCount *
51
- this.hourInMonth *
52
- this.selectedBillingCycle.to);
51
+ this.getTotalHours());
53
52
  }
54
53
  };
55
54
  SubscribedPricingPlanModel.prototype.getNetAmount = function (config) {
@@ -59,15 +58,13 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
59
58
  return Math.round(this.selectedPitchSlabBasePrice *
60
59
  (1 - this.getBillingDiscount() / 100) *
61
60
  this.pitchCount *
62
- this.hourInMonth *
63
- this.selectedBillingCycle.to);
61
+ this.getTotalHours());
64
62
  }
65
63
  else {
66
64
  return Math.floor(this.selectedPitchSlabBasePrice *
67
65
  (1 - this.getBillingDiscount() / 100) *
68
66
  this.pitchCount *
69
- this.hourInMonth *
70
- this.selectedBillingCycle.to);
67
+ this.getTotalHours());
71
68
  }
72
69
  };
73
70
  SubscribedPricingPlanModel.prototype.getBillingDiscount = function () {
@@ -117,6 +114,13 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
117
114
  SubscribedPricingPlanModel.prototype.getSelectedPitchSlabBasePrice = function () {
118
115
  return this.selectedPitchSlabBasePrice;
119
116
  };
117
+ SubscribedPricingPlanModel.prototype.getBasePriceBySelectedBillingCycleDiscount = function () {
118
+ return (this.selectedPitchSlabBasePrice -
119
+ math_util_1.mathUtil.getDiscountAmount(this.selectedBillingCycle.discount, this.selectedPitchSlabBasePrice));
120
+ };
121
+ SubscribedPricingPlanModel.prototype.getTotalHours = function () {
122
+ return this.hourInMonth * this.selectedBillingCycle.to;
123
+ };
120
124
  return SubscribedPricingPlanModel;
121
125
  }(pricing_plan_model_1.PricingPlanModel));
122
126
  exports.SubscribedPricingPlanModel = SubscribedPricingPlanModel;
@@ -0,0 +1,14 @@
1
+ declare class MathUtil {
2
+ /**
3
+ * Calculates the discount amount based on the provided coupon code and total cost.
4
+ *
5
+ * @param {string} couponCode - The coupon code used for the discount. If the code ends with "P", it's treated as a percentage discount. If it ends with "U", it's treated as a unit discount.
6
+ * @param {number} totalCost - The total cost before any discounts are applied.
7
+ * @param {boolean} [validationApply=false] - Decides whether to validate if the percentage discount is more than 90 or not.
8
+ * @returns {number} The calculated discount amount. If the couponCode ends with "P", the discount amount is the percentage of the totalCost. If the couponCode ends with "U", the discount amount is the parsed float value of the couponCode. If no couponCode is provided, the method returns 0. If the validationApply is true and the percentage discount is more than 90, it throws an AppBadRequestException with a message "Discount should not be more than 90P".
9
+ * @throws {AppBadRequestException} If validationApply is true and the percentage discount is more than 90.
10
+ */
11
+ getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
12
+ }
13
+ export declare const mathUtil: MathUtil;
14
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mathUtil = void 0;
4
+ var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
5
+ var MathUtil = /** @class */ (function () {
6
+ function MathUtil() {
7
+ }
8
+ /**
9
+ * Calculates the discount amount based on the provided coupon code and total cost.
10
+ *
11
+ * @param {string} couponCode - The coupon code used for the discount. If the code ends with "P", it's treated as a percentage discount. If it ends with "U", it's treated as a unit discount.
12
+ * @param {number} totalCost - The total cost before any discounts are applied.
13
+ * @param {boolean} [validationApply=false] - Decides whether to validate if the percentage discount is more than 90 or not.
14
+ * @returns {number} The calculated discount amount. If the couponCode ends with "P", the discount amount is the percentage of the totalCost. If the couponCode ends with "U", the discount amount is the parsed float value of the couponCode. If no couponCode is provided, the method returns 0. If the validationApply is true and the percentage discount is more than 90, it throws an AppBadRequestException with a message "Discount should not be more than 90P".
15
+ * @throws {AppBadRequestException} If validationApply is true and the percentage discount is more than 90.
16
+ */
17
+ MathUtil.prototype.getDiscountAmount = function (couponCode, totalCost, validationApply) {
18
+ if (validationApply === void 0) { validationApply = false; }
19
+ var discountAmount = 0;
20
+ if (couponCode) {
21
+ if (couponCode.slice(-1) === "P") {
22
+ var percentDiscount = parseFloat(couponCode);
23
+ if (validationApply && percentDiscount > 90) {
24
+ throw new app_badrequest_exception_1.AppBadRequestException({
25
+ key: "couponCode",
26
+ message: ["Discount should not be more than 90P"],
27
+ });
28
+ }
29
+ discountAmount = totalCost * (percentDiscount / 100);
30
+ }
31
+ else if (couponCode.slice(-1) === "U") {
32
+ discountAmount = parseFloat(couponCode);
33
+ }
34
+ }
35
+ return discountAmount;
36
+ };
37
+ return MathUtil;
38
+ }());
39
+ exports.mathUtil = new MathUtil();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turf-common",
3
- "version": "1.1.1-beta.52",
3
+ "version": "1.1.1-beta.53",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",