turf-common 1.1.1-beta.46 → 1.1.1-beta.48
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/@type.d.ts +1 -0
- package/build/@type.js +2 -0
- package/build/interface/ui/upgrade-subscription-data.interface.d.ts +15 -0
- package/build/interface/ui/upgrade-subscription-data.interface.js +2 -0
- package/build/models/billing-cycle-model.d.ts +1 -0
- package/build/models/billing-cycle-model.js +7 -0
- package/build/models/entity/subscription-model.d.ts +11 -0
- package/build/models/entity/subscription-model.js +106 -3
- package/build/models/pricing-plan-model.d.ts +3 -0
- package/build/models/pricing-plan-model.js +22 -0
- package/build/models/subscribed-pricing-plan-model.d.ts +5 -0
- package/build/models/subscribed-pricing-plan-model.js +13 -0
- package/build/utils/constant.d.ts +1 -0
- package/build/utils/constant.js +4 -0
- package/package.json +1 -1
package/build/@type.d.ts
CHANGED
|
@@ -27,3 +27,4 @@ export * from "./interface/without-token-registration-entity.types";
|
|
|
27
27
|
export * from "./interface/modify.interface";
|
|
28
28
|
export * from "./interface/modify-entity.interface";
|
|
29
29
|
export * from "./interface/key-value.interface";
|
|
30
|
+
export * from "./interface/ui/upgrade-subscription-data.interface";
|
package/build/@type.js
CHANGED
|
@@ -43,3 +43,5 @@ __exportStar(require("./interface/without-token-registration-entity.types"), exp
|
|
|
43
43
|
__exportStar(require("./interface/modify.interface"), exports);
|
|
44
44
|
__exportStar(require("./interface/modify-entity.interface"), exports);
|
|
45
45
|
__exportStar(require("./interface/key-value.interface"), exports);
|
|
46
|
+
// changes for the ui
|
|
47
|
+
__exportStar(require("./interface/ui/upgrade-subscription-data.interface"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ISubscriptionEntity } from "../entity";
|
|
2
|
+
export type PickOnly<T, K extends keyof T> = Pick<T, K> & {
|
|
3
|
+
[P in Exclude<keyof T, K>]?: never;
|
|
4
|
+
};
|
|
5
|
+
export type UpgradeSubscriptionData = PickOnly<ISubscriptionEntity, "from" | "to" | "noOfPitches" | "netAmount" | "grossAmount" | "organizationId" | "pricingPlanId" | "registrationId" | "type" | "previousSubscriptionIds" | "amountPaid" | "discount"> & {
|
|
6
|
+
newlyAddedPitchCount: number;
|
|
7
|
+
basePrice: number;
|
|
8
|
+
remainingSubscriptionDays: number;
|
|
9
|
+
additionalGrossAmount: number;
|
|
10
|
+
};
|
|
11
|
+
export type RenewSubscriptionData = PickOnly<ISubscriptionEntity, "noOfPitches" | "netAmount" | "grossAmount" | "organizationId" | "pricingPlanId" | "registrationId" | "type" | "previousSubscriptionIds" | "amountPaid" | "discount"> & {
|
|
12
|
+
fromDate: Date;
|
|
13
|
+
toDate: Date;
|
|
14
|
+
basePrice: number;
|
|
15
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BillingCycleModel = void 0;
|
|
4
|
+
var date_util_1 = require("../utils/date-util");
|
|
4
5
|
var BillingCycleModel = /** @class */ (function () {
|
|
5
6
|
function BillingCycleModel(data) {
|
|
6
7
|
this.from = data.from;
|
|
@@ -15,6 +16,12 @@ var BillingCycleModel = /** @class */ (function () {
|
|
|
15
16
|
}
|
|
16
17
|
return 0;
|
|
17
18
|
};
|
|
19
|
+
BillingCycleModel.prototype.getBillingCycle = function (date) {
|
|
20
|
+
// const dateUtilService = AppInjector.get(DateUtilService);
|
|
21
|
+
var startDate = date_util_1.dateUtilService.addNDaysToDate(date, 1);
|
|
22
|
+
var endDate = date_util_1.dateUtilService.addNDaysToDate(startDate, this.to * 30);
|
|
23
|
+
return [startDate, endDate];
|
|
24
|
+
};
|
|
18
25
|
return BillingCycleModel;
|
|
19
26
|
}());
|
|
20
27
|
exports.BillingCycleModel = BillingCycleModel;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { IGetCurrentSubscriptionResponse, ISubscriptionPitchMappingEntity } from "../../@type";
|
|
1
2
|
import { SubscriptionStatus } from "../../enums/subscription-status.enum";
|
|
2
3
|
import { ISubscriptionEntity, ISubscriptionModel } from "../../interface/entity/subscription-entity.interface";
|
|
4
|
+
import { RenewSubscriptionData, UpgradeSubscriptionData } from "../../interface/ui/upgrade-subscription-data.interface";
|
|
5
|
+
import { PricingPlanModel } from "../pricing-plan-model";
|
|
6
|
+
import { SubscribedPricingPlanModel } from "../subscribed-pricing-plan-model";
|
|
3
7
|
export declare class SubscriptionModel implements ISubscriptionModel {
|
|
4
8
|
id: number;
|
|
5
9
|
organizationId: number;
|
|
@@ -22,8 +26,15 @@ export declare class SubscriptionModel implements ISubscriptionModel {
|
|
|
22
26
|
updatedBy: number;
|
|
23
27
|
fromDateCode: string;
|
|
24
28
|
toDateCode: string;
|
|
29
|
+
details?: ISubscriptionPitchMappingEntity[];
|
|
25
30
|
constructor(data: ISubscriptionEntity);
|
|
31
|
+
static getInstanceByResponse(data: IGetCurrentSubscriptionResponse): SubscriptionModel;
|
|
32
|
+
getFromDate(): Date;
|
|
33
|
+
getToDate(): Date;
|
|
34
|
+
isRenewalDue(): boolean;
|
|
26
35
|
remainingSubscriptionDays(): number;
|
|
36
|
+
upgradeSubscription(totalPitchCount: number, subscribedPricingModel: SubscribedPricingPlanModel): UpgradeSubscriptionData;
|
|
37
|
+
renewSubscription(totalPitchCount: number, billingCycle: string, currentPricingPlanModel: PricingPlanModel): RenewSubscriptionData;
|
|
27
38
|
static updateStatus(subscriptionEntities: ISubscriptionEntity[], status: SubscriptionStatus, userId: number): ISubscriptionEntity[];
|
|
28
39
|
remainingAmount(): number;
|
|
29
40
|
isAmountFullyPaid(): boolean;
|
|
@@ -1,15 +1,118 @@
|
|
|
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
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.SubscriptionModel = void 0;
|
|
4
15
|
var subscription_status_enum_1 = require("../../enums/subscription-status.enum");
|
|
16
|
+
var constant_1 = require("../../utils/constant");
|
|
17
|
+
var date_util_1 = require("../../utils/date-util");
|
|
18
|
+
var subscribed_pricing_plan_model_1 = require("../subscribed-pricing-plan-model");
|
|
5
19
|
var SubscriptionModel = /** @class */ (function () {
|
|
6
20
|
function SubscriptionModel(data) {
|
|
7
21
|
Object.assign(this, data);
|
|
8
22
|
}
|
|
23
|
+
SubscriptionModel.getInstanceByResponse = function (data) {
|
|
24
|
+
// this.id = data.id;
|
|
25
|
+
// this.organizationId = data.organizationId;
|
|
26
|
+
// this.from = data.from;
|
|
27
|
+
// this.to = data.to;
|
|
28
|
+
// this.type = data.type;
|
|
29
|
+
// this.grossAmount = data.grossAmount;
|
|
30
|
+
// this.discount = data.discount;
|
|
31
|
+
// this.netAmount = data.netAmount;
|
|
32
|
+
// this.amountPaid = data.amountPaid;
|
|
33
|
+
// this.status = data.status;
|
|
34
|
+
// this.noOfPitches = data.noOfPitches;
|
|
35
|
+
// this.createdBy = data.createdBy;
|
|
36
|
+
// this.createdOn = data.createdOn;
|
|
37
|
+
// this.updatedBy = data.updatedBy;
|
|
38
|
+
// this.updatedOn = data.updatedOn;
|
|
39
|
+
// this.remarks = data.remarks;
|
|
40
|
+
// this.registrationId = data.registrationId;
|
|
41
|
+
// this.pricingPlanId = data.pricingPlanId;
|
|
42
|
+
// this.upgradeSubscriptionId = Number(data.previousSubscriptionIds);
|
|
43
|
+
// this.details = data.details;
|
|
44
|
+
var demo = __assign(__assign({}, data), { from: date_util_1.dateUtilService.getDateFromDatabaseDate(data.from), to: date_util_1.dateUtilService.getDateFromDatabaseDate(data.to), createdOn: date_util_1.dateUtilService.getDateFromDatabaseDate(data.createdOn), updatedOn: date_util_1.dateUtilService.getDateFromDatabaseDate(data.updatedOn) });
|
|
45
|
+
return new SubscriptionModel(demo);
|
|
46
|
+
};
|
|
47
|
+
SubscriptionModel.prototype.getFromDate = function () {
|
|
48
|
+
return this.from;
|
|
49
|
+
};
|
|
50
|
+
SubscriptionModel.prototype.getToDate = function () {
|
|
51
|
+
return this.to;
|
|
52
|
+
};
|
|
53
|
+
SubscriptionModel.prototype.isRenewalDue = function () {
|
|
54
|
+
// Check if difference 'to' date and today's date is less than 7 days
|
|
55
|
+
return (this.getToDate().getTime() - new Date().getTime() <
|
|
56
|
+
constant_1.SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS * 24 * 60 * 60 * 1000);
|
|
57
|
+
};
|
|
9
58
|
SubscriptionModel.prototype.remainingSubscriptionDays = function () {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
59
|
+
// const oneDay = 24 * 60 * 60 * 1000;
|
|
60
|
+
// const dayDifference = Math.ceil(
|
|
61
|
+
// (this.to.getTime() - new Date().getTime()) / oneDay
|
|
62
|
+
// );
|
|
63
|
+
// return dayDifference - 1; //minus 1 day
|
|
64
|
+
return date_util_1.dateUtilService.noOfDaysBetweenDates(new Date(), this.getToDate());
|
|
65
|
+
};
|
|
66
|
+
SubscriptionModel.prototype.upgradeSubscription = function (totalPitchCount, subscribedPricingModel) {
|
|
67
|
+
var newlyAddedPitchCount = totalPitchCount - this.noOfPitches;
|
|
68
|
+
var basePrice = subscribedPricingModel.getSelectedPitchSlabBasePrice();
|
|
69
|
+
var remainingSubscriptionDays = this.remainingSubscriptionDays();
|
|
70
|
+
var additionalGrossAmount = basePrice * remainingSubscriptionDays * 24 * newlyAddedPitchCount;
|
|
71
|
+
return {
|
|
72
|
+
amountPaid: this.amountPaid,
|
|
73
|
+
discount: this.discount,
|
|
74
|
+
from: this.from,
|
|
75
|
+
to: this.to,
|
|
76
|
+
noOfPitches: totalPitchCount,
|
|
77
|
+
netAmount: Math.round(this.netAmount + additionalGrossAmount),
|
|
78
|
+
grossAmount: Math.round(this.grossAmount + additionalGrossAmount),
|
|
79
|
+
organizationId: this.organizationId,
|
|
80
|
+
pricingPlanId: this.pricingPlanId,
|
|
81
|
+
registrationId: this.registrationId,
|
|
82
|
+
type: this.type,
|
|
83
|
+
previousSubscriptionIds: this.id.toString(),
|
|
84
|
+
newlyAddedPitchCount: newlyAddedPitchCount,
|
|
85
|
+
basePrice: basePrice,
|
|
86
|
+
remainingSubscriptionDays: remainingSubscriptionDays,
|
|
87
|
+
additionalGrossAmount: Math.round(additionalGrossAmount),
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
SubscriptionModel.prototype.renewSubscription = function (totalPitchCount, billingCycle, currentPricingPlanModel) {
|
|
91
|
+
// const dateUtilService = new DateUtilService();
|
|
92
|
+
// dateService.convertStringToDate(this.from, "yyyy-MM-dd");
|
|
93
|
+
// const subscribedPitchCount: number = this.noOfPitches;
|
|
94
|
+
var renewalSubscriptionModel = new subscribed_pricing_plan_model_1.SubscribedPricingPlanModel(currentPricingPlanModel, totalPitchCount, billingCycle);
|
|
95
|
+
var toDate = this.to;
|
|
96
|
+
var _a = renewalSubscriptionModel.getNextBillingCycleDateRange(toDate), startDate = _a[0], endDate = _a[1];
|
|
97
|
+
// const [startDateCode, endDateCode]: [string, string] = [
|
|
98
|
+
// dateService.getDateCode(startDate),
|
|
99
|
+
// dateService.getDateCode(endDate),
|
|
100
|
+
// ];
|
|
101
|
+
return {
|
|
102
|
+
amountPaid: 0,
|
|
103
|
+
discount: renewalSubscriptionModel.selectedBillingCycle.discount,
|
|
104
|
+
fromDate: startDate,
|
|
105
|
+
grossAmount: Math.round(renewalSubscriptionModel.getGrossAmount()),
|
|
106
|
+
netAmount: Math.round(renewalSubscriptionModel.getNetAmount()),
|
|
107
|
+
noOfPitches: totalPitchCount,
|
|
108
|
+
pricingPlanId: currentPricingPlanModel.id,
|
|
109
|
+
toDate: endDate,
|
|
110
|
+
type: billingCycle,
|
|
111
|
+
organizationId: this.organizationId,
|
|
112
|
+
registrationId: this.registrationId,
|
|
113
|
+
previousSubscriptionIds: null,
|
|
114
|
+
basePrice: renewalSubscriptionModel.getSelectedPitchSlabBasePrice(),
|
|
115
|
+
};
|
|
13
116
|
};
|
|
14
117
|
SubscriptionModel.updateStatus = function (subscriptionEntities, status, userId) {
|
|
15
118
|
return subscriptionEntities.map(function (subscriptionEntity) {
|
|
@@ -21,4 +21,7 @@ export declare class PricingPlanModel implements IPricingPlanModel {
|
|
|
21
21
|
getBillingCycleKeys(): string[];
|
|
22
22
|
validateBillingCycleKey(billingCycleKey: string): void;
|
|
23
23
|
getBillingCycleByDay(numberOfDay: number): BillingCycleModel | undefined;
|
|
24
|
+
getPitchSlabIndex(pitchCount: number): number;
|
|
25
|
+
formatPitchSlab(index: number): string;
|
|
26
|
+
getBillingCycleIndexByMonths(noOfMonths: number): number;
|
|
24
27
|
}
|
|
@@ -62,6 +62,28 @@ var PricingPlanModel = /** @class */ (function () {
|
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
|
+
PricingPlanModel.prototype.getPitchSlabIndex = function (pitchCount) {
|
|
66
|
+
var pitchRangesMap = this.pitch_slab;
|
|
67
|
+
var pitchRanges = Object.values(pitchRangesMap);
|
|
68
|
+
return pitchRanges.findIndex(function (pitchRange) {
|
|
69
|
+
return pitchRange.from <= pitchCount && pitchCount <= pitchRange.to;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
PricingPlanModel.prototype.formatPitchSlab = function (index) {
|
|
73
|
+
var pitchRangesMap = this.pitch_slab;
|
|
74
|
+
var pitchRanges = Object.values(pitchRangesMap);
|
|
75
|
+
var selectedPitchSlab = pitchRanges[index];
|
|
76
|
+
if (index === pitchRanges.length - 1) {
|
|
77
|
+
return "".concat(selectedPitchSlab.from - 1, "+");
|
|
78
|
+
}
|
|
79
|
+
return "".concat(selectedPitchSlab.from, "-").concat(selectedPitchSlab.to);
|
|
80
|
+
};
|
|
81
|
+
PricingPlanModel.prototype.getBillingCycleIndexByMonths = function (noOfMonths) {
|
|
82
|
+
return Object.values(this.billing_cycle).findIndex(function (_a) {
|
|
83
|
+
var from = _a.from, to = _a.to;
|
|
84
|
+
return from <= noOfMonths && noOfMonths <= to;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
65
87
|
return PricingPlanModel;
|
|
66
88
|
}());
|
|
67
89
|
exports.PricingPlanModel = PricingPlanModel;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { IGetPricingPlanByDateResponse } from "../@type";
|
|
1
2
|
import { IPricingPlanModel } from "../interface/pricing-plan.interface";
|
|
2
3
|
import { BillingCycleModel } from "./billing-cycle-model";
|
|
4
|
+
import { SubscriptionModel } from "./entity";
|
|
3
5
|
import { PitchSlabModel } from "./pitch-slab-model";
|
|
4
6
|
import { PricingPlanModel } from "./pricing-plan-model";
|
|
5
7
|
export declare class SubscribedPricingPlanModel extends PricingPlanModel {
|
|
@@ -23,4 +25,7 @@ export declare class SubscribedPricingPlanModel extends PricingPlanModel {
|
|
|
23
25
|
getNetAmountByPitchDays(pitchCount: number, days: number): number;
|
|
24
26
|
getGrossAmountByPitchDaysBasePrice(basePrice: number, pitchCount: number, days: number): number;
|
|
25
27
|
getNetAmountByPitchDaysBasePrice(basePrice: number, pitchCount: number, days: number): number;
|
|
28
|
+
getNextBillingCycleDateRange(date: Date): [Date, Date];
|
|
29
|
+
static getInstanceBySubscriptionData(data: IGetPricingPlanByDateResponse, subscriptionDataModel: SubscriptionModel): SubscribedPricingPlanModel;
|
|
30
|
+
getSelectedPitchSlabBasePrice(): number;
|
|
26
31
|
}
|
|
@@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SubscribedPricingPlanModel = void 0;
|
|
19
|
+
var date_util_1 = require("../utils/date-util");
|
|
19
20
|
var pricing_plan_model_1 = require("./pricing-plan-model");
|
|
20
21
|
var SubscribedPricingPlanModel = /** @class */ (function (_super) {
|
|
21
22
|
__extends(SubscribedPricingPlanModel, _super);
|
|
@@ -83,6 +84,18 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
|
|
|
83
84
|
SubscribedPricingPlanModel.prototype.getNetAmountByPitchDaysBasePrice = function (basePrice, pitchCount, days) {
|
|
84
85
|
return Math.round(basePrice * (1 - this.getBillingDiscount() / 100) * pitchCount * days * 24);
|
|
85
86
|
};
|
|
87
|
+
SubscribedPricingPlanModel.prototype.getNextBillingCycleDateRange = function (date) {
|
|
88
|
+
// const dateService = new DateUtilService();
|
|
89
|
+
var startDate = date_util_1.dateUtilService.addNDaysToDate(date, 1);
|
|
90
|
+
var endDate = date_util_1.dateUtilService.addNDaysToDate(date, this.selectedBillingCycle.to * 30);
|
|
91
|
+
return [startDate, endDate];
|
|
92
|
+
};
|
|
93
|
+
SubscribedPricingPlanModel.getInstanceBySubscriptionData = function (data, subscriptionDataModel) {
|
|
94
|
+
return new SubscribedPricingPlanModel(data, subscriptionDataModel.noOfPitches, subscriptionDataModel.type);
|
|
95
|
+
};
|
|
96
|
+
SubscribedPricingPlanModel.prototype.getSelectedPitchSlabBasePrice = function () {
|
|
97
|
+
return this.selectedPitchSlabBasePrice;
|
|
98
|
+
};
|
|
86
99
|
return SubscribedPricingPlanModel;
|
|
87
100
|
}(pricing_plan_model_1.PricingPlanModel));
|
|
88
101
|
exports.SubscribedPricingPlanModel = SubscribedPricingPlanModel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SUBSCRIPTION_RENEWAL_THRESHOLD_DAYS = 7;
|