ia-common 1.0.1-beta.17 → 1.0.1-beta.19

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.
@@ -0,0 +1,2 @@
1
+ export * from "./model/pricing-plan-entity-model";
2
+ export * from "./model/subscribed-pricing-plan-model";
@@ -0,0 +1,18 @@
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("./model/pricing-plan-entity-model"), exports);
18
+ __exportStar(require("./model/subscribed-pricing-plan-model"), exports);
@@ -0,0 +1,4 @@
1
+ import { IAppBadRequestException } from "../interface/app-badrequest-exception.type";
2
+ export declare class AppBadRequestException extends Error {
3
+ constructor(appBadRequestException: IAppBadRequestException);
4
+ }
@@ -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.message = appBadRequestException.message.join(",");
24
+ return _this;
25
+ }
26
+ return AppBadRequestException;
27
+ }(Error));
28
+ exports.AppBadRequestException = AppBadRequestException;
@@ -14,3 +14,4 @@ export * from "./get-registration-by-id.interface";
14
14
  export * from "./get-registration-with-organization-owners.interface";
15
15
  export * from "./remove-bank-details-by-id.interface";
16
16
  export * from "./update-pricing-plan-by-id.interface";
17
+ export * from "./login.interface";
@@ -30,3 +30,4 @@ __exportStar(require("./get-registration-by-id.interface"), exports);
30
30
  __exportStar(require("./get-registration-with-organization-owners.interface"), exports);
31
31
  __exportStar(require("./remove-bank-details-by-id.interface"), exports);
32
32
  __exportStar(require("./update-pricing-plan-by-id.interface"), exports);
33
+ __exportStar(require("./login.interface"), exports);
@@ -0,0 +1,22 @@
1
+ export interface ILoginResponse {
2
+ UIMessage: string;
3
+ tokenType: string;
4
+ accessToken: string;
5
+ id: string;
6
+ firstname: string;
7
+ status: string;
8
+ requireNewPassword: boolean;
9
+ userId: number;
10
+ role: string;
11
+ email: string | null;
12
+ imageUrl: string | null;
13
+ userPermissions: string[];
14
+ registrationId: number;
15
+ organizationId: number;
16
+ subscriptionStatus: string | null;
17
+ contact: string;
18
+ }
19
+ export interface ILoginRequest {
20
+ username: string;
21
+ password: string;
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type IAppBadRequestException = {
2
+ key: string;
3
+ message: string[];
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,65 @@
1
+ import { PricingPlanStatus } from "../@enum";
2
+ import { IGetPricingPlanByDateResponse, IPricingPlanEntity } from "../@type";
3
+ export declare class PricingPlanEntityModel {
4
+ id: number;
5
+ effectiveFrom: number;
6
+ effectiveTo: number;
7
+ status: PricingPlanStatus;
8
+ createdBy: number;
9
+ createdOn: Date;
10
+ updatedBy: number;
11
+ updatedOn: Date;
12
+ basePrice: number;
13
+ billingCycle: string;
14
+ constructor(data: IPricingPlanEntity);
15
+ toObject(): IGetPricingPlanByDateResponse;
16
+ }
17
+ export declare class BillingCycleModel {
18
+ code: string;
19
+ noOfMonths: number;
20
+ discount: string;
21
+ name: string;
22
+ key: string;
23
+ constructor(code: string);
24
+ parse(): BillingCycleModel;
25
+ getDiscount(): number;
26
+ getKey(): string;
27
+ }
28
+ export interface IPricingPlanModel {
29
+ id: number;
30
+ effectiveFromDate: number;
31
+ effectiveToDate: number;
32
+ basePrice: number;
33
+ billingCycle: {
34
+ [key: string]: {
35
+ noOfMonths: number;
36
+ discount: string;
37
+ name: string;
38
+ key: string;
39
+ };
40
+ };
41
+ }
42
+ export declare class PricingPlanModel implements IPricingPlanModel {
43
+ id: number;
44
+ effectiveFromDate: number;
45
+ effectiveToDate: number;
46
+ basePrice: number;
47
+ billingCycle: {
48
+ [key: string]: {
49
+ noOfMonths: number;
50
+ discount: string;
51
+ name: string;
52
+ key: string;
53
+ };
54
+ };
55
+ constructor(data: IGetPricingPlanByDateResponse);
56
+ getBillingCycleKeys(): string[];
57
+ getNoOfSubscriptionDays(type: string): number;
58
+ getBillCycleByKey(type: string): {
59
+ noOfMonths: number;
60
+ discount: string;
61
+ name: string;
62
+ key: string;
63
+ };
64
+ validateBillingCycleKey(key: string): void;
65
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PricingPlanModel = exports.BillingCycleModel = exports.PricingPlanEntityModel = void 0;
4
+ var app_badrequest_exception_1 = require("../exception/app-badrequest.exception");
5
+ var PricingPlanEntityModel = /** @class */ (function () {
6
+ function PricingPlanEntityModel(data) {
7
+ Object.assign(this, data);
8
+ }
9
+ PricingPlanEntityModel.prototype.toObject = function () {
10
+ var responseObj = {
11
+ id: this.id,
12
+ effectiveFromDate: 0,
13
+ effectiveToDate: 0,
14
+ basePrice: 0,
15
+ billingCycle: {},
16
+ };
17
+ var billingCycle = this.billingCycle.split(",");
18
+ billingCycle.forEach(function (billing, index) {
19
+ var billingArray = billing.split("_");
20
+ responseObj.billingCycle[index] = {
21
+ noOfMonths: Number(billingArray[0]),
22
+ discount: billingArray[1],
23
+ name: billingArray.slice(2).join("_"),
24
+ key: billingArray.slice(2).join("-").toLowerCase().replace(/ /g, "-"),
25
+ };
26
+ });
27
+ responseObj.effectiveFromDate = this.effectiveFrom;
28
+ responseObj.effectiveToDate = this.effectiveTo;
29
+ responseObj.basePrice = this.basePrice;
30
+ return responseObj;
31
+ };
32
+ return PricingPlanEntityModel;
33
+ }());
34
+ exports.PricingPlanEntityModel = PricingPlanEntityModel;
35
+ var BillingCycleModel = /** @class */ (function () {
36
+ function BillingCycleModel(code) {
37
+ this.code = code;
38
+ this.parse();
39
+ }
40
+ BillingCycleModel.prototype.parse = function () {
41
+ var billingCycleComponents = this.code.split("_");
42
+ this.noOfMonths = Number(billingCycleComponents[0]);
43
+ this.discount = billingCycleComponents[1];
44
+ this.name = billingCycleComponents[2];
45
+ this.key = this.getKey();
46
+ return this;
47
+ };
48
+ BillingCycleModel.prototype.getDiscount = function () {
49
+ if (this.discount.indexOf("P") > -1) {
50
+ return parseFloat(this.discount.replace("P", ""));
51
+ }
52
+ return 0;
53
+ };
54
+ BillingCycleModel.prototype.getKey = function () {
55
+ return this.name.toLowerCase().replace(" ", "-");
56
+ };
57
+ return BillingCycleModel;
58
+ }());
59
+ exports.BillingCycleModel = BillingCycleModel;
60
+ var PricingPlanModel = /** @class */ (function () {
61
+ function PricingPlanModel(data) {
62
+ Object.assign(this, data);
63
+ }
64
+ PricingPlanModel.prototype.getBillingCycleKeys = function () {
65
+ return Object.values(this.billingCycle).map(function (billingCycleObj) { return billingCycleObj.key; });
66
+ };
67
+ PricingPlanModel.prototype.getNoOfSubscriptionDays = function (type) {
68
+ var billingCycleModel = this.getBillCycleByKey(type);
69
+ return billingCycleModel.noOfMonths * 30 - 1;
70
+ };
71
+ PricingPlanModel.prototype.getBillCycleByKey = function (type) {
72
+ return Object.values(this.billingCycle).filter(function (billingCycleObj) { return billingCycleObj.key === type; })[0];
73
+ };
74
+ PricingPlanModel.prototype.validateBillingCycleKey = function (key) {
75
+ if (!this.getBillingCycleKeys().includes(key)) {
76
+ throw new app_badrequest_exception_1.AppBadRequestException({
77
+ key: "type",
78
+ message: [
79
+ "subscription with type:'".concat(key, "' is wrong,type should be one of the ").concat(this.getBillingCycleKeys()),
80
+ ],
81
+ });
82
+ }
83
+ };
84
+ return PricingPlanModel;
85
+ }());
86
+ exports.PricingPlanModel = PricingPlanModel;
@@ -0,0 +1,20 @@
1
+ import { PricingPlanModel } from "./pricing-plan-entity-model";
2
+ export declare class SubscribedPricingPlanModel extends PricingPlanModel {
3
+ billingCycleKey: string;
4
+ selectedBillingCycle: {
5
+ noOfMonths: number;
6
+ discount: string;
7
+ name: string;
8
+ key: string;
9
+ };
10
+ selectedPitchSlabBasePrice: number;
11
+ constructor(data: PricingPlanModel, billingCycleKey: string);
12
+ getBasePrice(): number;
13
+ getGrossAmount(config?: {
14
+ roundDown: boolean;
15
+ }): number;
16
+ getNetAmount(config?: {
17
+ roundDown: boolean;
18
+ }): number;
19
+ getBillingDiscount(): number;
20
+ }
@@ -0,0 +1,63 @@
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.SubscribedPricingPlanModel = void 0;
19
+ var pricing_plan_entity_model_1 = require("./pricing-plan-entity-model");
20
+ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
21
+ __extends(SubscribedPricingPlanModel, _super);
22
+ function SubscribedPricingPlanModel(data, billingCycleKey) {
23
+ var _this = _super.call(this, data) || this;
24
+ _this.billingCycleKey = billingCycleKey;
25
+ _this.selectedBillingCycle = data.getBillCycleByKey(billingCycleKey);
26
+ return _this;
27
+ }
28
+ SubscribedPricingPlanModel.prototype.getBasePrice = function () {
29
+ return this.selectedPitchSlabBasePrice;
30
+ };
31
+ SubscribedPricingPlanModel.prototype.getGrossAmount = function (config) {
32
+ if (config === void 0) { config = { roundDown: false }; }
33
+ var roundDown = config.roundDown;
34
+ if (roundDown) {
35
+ return Math.floor(this.basePrice * this.selectedBillingCycle.noOfMonths);
36
+ }
37
+ else {
38
+ return Math.round(this.basePrice * this.selectedBillingCycle.noOfMonths);
39
+ }
40
+ };
41
+ SubscribedPricingPlanModel.prototype.getNetAmount = function (config) {
42
+ if (config === void 0) { config = { roundDown: false }; }
43
+ var roundDown = config.roundDown;
44
+ if (roundDown) {
45
+ return Math.floor(this.basePrice *
46
+ (1 - this.getBillingDiscount() / 100) *
47
+ this.selectedBillingCycle.noOfMonths);
48
+ }
49
+ else {
50
+ return Math.round(this.basePrice *
51
+ (1 - this.getBillingDiscount() / 100) *
52
+ this.selectedBillingCycle.noOfMonths);
53
+ }
54
+ };
55
+ SubscribedPricingPlanModel.prototype.getBillingDiscount = function () {
56
+ if (this.selectedBillingCycle.discount.indexOf("P") > -1) {
57
+ return parseFloat(this.selectedBillingCycle.discount.replace("P", ""));
58
+ }
59
+ return 0;
60
+ };
61
+ return SubscribedPricingPlanModel;
62
+ }(pricing_plan_entity_model_1.PricingPlanModel));
63
+ exports.SubscribedPricingPlanModel = SubscribedPricingPlanModel;
@@ -0,0 +1,8 @@
1
+ export declare class DateUtil {
2
+ static isValidDate(dateCode: string): boolean;
3
+ getDateCode(date: Date): string;
4
+ convertStringToDate(dateString: string, format?: string): Date;
5
+ addNDaysToDate(date: Date, n: number): Date;
6
+ addNDaysToDateCode(dateCode: string, n: number): string;
7
+ }
8
+ export declare const dateUtil: DateUtil;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dateUtil = exports.DateUtil = void 0;
4
+ var date_fns_1 = require("date-fns");
5
+ var DateUtil = /** @class */ (function () {
6
+ function DateUtil() {
7
+ }
8
+ DateUtil.isValidDate = function (dateCode) {
9
+ if (dateCode.length !== 6)
10
+ return false;
11
+ // Date format: YYMMDD
12
+ function isDate(dateString) {
13
+ var separators = ["\\.", "\\-", "\\/"];
14
+ var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
15
+ var intBits = stringBits.map(function (bit) { return parseInt(bit); });
16
+ var parsedDate = new Date(intBits[0], intBits[1] - 1, intBits[2]);
17
+ return (parsedDate.getFullYear() === intBits[0] &&
18
+ parsedDate.getMonth() + 1 === intBits[1] &&
19
+ parsedDate.getDate() === intBits[2]);
20
+ }
21
+ return isDate("20".concat(dateCode.slice(0, 2), ".").concat(dateCode.slice(2, 4), ".").concat(dateCode.slice(4, 6)));
22
+ };
23
+ DateUtil.prototype.getDateCode = function (date) {
24
+ return (0, date_fns_1.format)(date, "yyMMdd");
25
+ };
26
+ DateUtil.prototype.convertStringToDate = function (dateString, format) {
27
+ if (format === void 0) { format = "yyMMdd"; }
28
+ var parsedDate = (0, date_fns_1.parse)(dateString, format, new Date());
29
+ // IST has a fixed offset of UTC+5:30
30
+ var indianDate = new Date(parsedDate.getTime() + 330 * 60 * 1000);
31
+ return indianDate;
32
+ };
33
+ DateUtil.prototype.addNDaysToDate = function (date, n) {
34
+ return (0, date_fns_1.add)(date, { days: n });
35
+ };
36
+ DateUtil.prototype.addNDaysToDateCode = function (dateCode, n) {
37
+ return this.getDateCode(this.addNDaysToDate(this.convertStringToDate(dateCode, "yyMMdd"), n));
38
+ };
39
+ return DateUtil;
40
+ }());
41
+ exports.DateUtil = DateUtil;
42
+ exports.dateUtil = new DateUtil();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ia-common",
3
- "version": "1.0.1-beta.17",
3
+ "version": "1.0.1-beta.19",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -30,5 +30,8 @@
30
30
  "del-cli": "^5.1.0",
31
31
  "eslint": "^8.56.0",
32
32
  "typescript": "^5.3.3"
33
+ },
34
+ "dependencies": {
35
+ "date-fns": "^3.3.1"
33
36
  }
34
37
  }