@nimee/calculations 1.0.5 → 1.0.7
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/dist/prices.d.ts +1 -1
- package/dist/prices.js +30 -32
- package/dist/prices.js.map +1 -1
- package/package.json +2 -2
- package/src/prices.ts +29 -24
package/dist/prices.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare const calculateFinalPriceWithNimiFee: (totalPriceWithoutCouponDis
|
|
|
6
6
|
finalPriceWithNimiFee: number;
|
|
7
7
|
};
|
|
8
8
|
export declare const calculateFinalPriceWithCouponDiscount: (totalPrice: number, couponDiscount: number) => number;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const calculateFinalPriceWithEndUserSeasonTicket: (totalPrice: number, endUserSeasonTicketDiscountPrice: any) => number;
|
package/dist/prices.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
3
|
+
exports.calculateFinalPriceWithEndUserSeasonTicket = exports.calculateFinalPriceWithCouponDiscount = exports.calculateFinalPriceWithNimiFee = exports.getTotalTicketsAmount = void 0;
|
|
13
4
|
/* Central the prices logic so we won't repeat it */
|
|
14
5
|
const shared_types_1 = require("@nimee/shared-types");
|
|
15
|
-
const api_clients_1 = require("@nimee/api-clients");
|
|
16
|
-
const error_handler_1 = require("@nimee/error-handler");
|
|
17
6
|
// Support both legacy and new userEvent schema (with ticketsInfo and without.)
|
|
18
7
|
const getTotalTicketsAmount = (allUsersEvent) => {
|
|
19
8
|
return allUsersEvent.reduce((acc, userEvent) => {
|
|
@@ -36,7 +25,11 @@ const calculateFinalPriceWithNimiFee = (totalPriceWithoutCouponDiscount, event,
|
|
|
36
25
|
case shared_types_1.IFeeCollectionType.PERCENTAGE_FROM_TICKET:
|
|
37
26
|
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee }; // we use here marketFee (and not originalMarketFee) because we need to send the fee to payme without their fee
|
|
38
27
|
case shared_types_1.IFeeCollectionType.ON_TOP_OF_TICKET:
|
|
39
|
-
//
|
|
28
|
+
// check if the totalPrice with coupon discount is 0 then we return 0 for the fee and the percentage
|
|
29
|
+
if (totalPriceWithCouponDiscount === 0) {
|
|
30
|
+
return { finalPriceWithNimiFee: 0, nimiFee: 0, nimiFeePercentage: 0 };
|
|
31
|
+
}
|
|
32
|
+
// minimum 3 so we use max we totalPriceWithoutCouponDiscount because the fee is calculated on top of the original price and not the price after discount
|
|
40
33
|
const unroundedFee = Math.max(3, (totalPriceWithoutCouponDiscount * account.originalMarketFee) / 100); // here we use originalMarketFee because we need to calculate the fee on top of the original price (later we will subtract payme fee from the fee we send to payme)
|
|
41
34
|
const roundedFee = Math.round(unroundedFee);
|
|
42
35
|
// nimiFeePercentage has unknown range that need to be aware of - we get error when we send to payme with range above 60 so we use max
|
|
@@ -55,25 +48,30 @@ const calculateFinalPriceWithNimiFee = (totalPriceWithoutCouponDiscount, event,
|
|
|
55
48
|
exports.calculateFinalPriceWithNimiFee = calculateFinalPriceWithNimiFee;
|
|
56
49
|
const calculateFinalPriceWithCouponDiscount = (totalPrice, couponDiscount) => totalPrice - couponDiscount < 0 ? 0 : totalPrice - couponDiscount;
|
|
57
50
|
exports.calculateFinalPriceWithCouponDiscount = calculateFinalPriceWithCouponDiscount;
|
|
51
|
+
const calculateFinalPriceWithEndUserSeasonTicket = (totalPrice, endUserSeasonTicketDiscountPrice) => totalPrice - endUserSeasonTicketDiscountPrice < 0 ? 0 : totalPrice - endUserSeasonTicketDiscountPrice;
|
|
52
|
+
exports.calculateFinalPriceWithEndUserSeasonTicket = calculateFinalPriceWithEndUserSeasonTicket;
|
|
58
53
|
// Validate the order is really free, rather the tickets free or with the coupon discount.
|
|
59
54
|
// we do this so the client won't be able to create orders with price 0 and it won't be validated
|
|
60
|
-
const validateFreeOrder = (ticketIds, couponDiscount, accountId, eventId) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
// export const validateFreeOrder = async (ticketIds: string[], couponDiscount: number, accountId: string, eventId: string) => {
|
|
56
|
+
// const ticketClient = new TicketClient();
|
|
57
|
+
// const tickets = await ticketClient.getTicketsByIds({ token: process.env.JWT_ADMIN, ticketIds, accountId, eventId });
|
|
58
|
+
// if (!tickets?.length) {
|
|
59
|
+
// throw new CustomError(
|
|
60
|
+
// "tickets_not_found_validate_free_order",
|
|
61
|
+
// 400,
|
|
62
|
+
// `tickets not found when try to validate free order with ticketIds - ${ticketIds} and eventId - ${eventId}`
|
|
63
|
+
// );
|
|
64
|
+
// }
|
|
65
|
+
// const rawOrderPriceFromTickets = tickets.reduce((acc: number, ticket: { price: number }) => acc + ticket.price, 0);
|
|
66
|
+
// if (rawOrderPriceFromTickets === 0) {
|
|
67
|
+
// return true;
|
|
68
|
+
// }
|
|
69
|
+
// if (couponDiscount) {
|
|
70
|
+
// const orderPriceAfterCoupon = calculateFinalPriceWithCouponDiscount(rawOrderPriceFromTickets, couponDiscount);
|
|
71
|
+
// if (orderPriceAfterCoupon === 0) {
|
|
72
|
+
// return true;
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
// return false;
|
|
76
|
+
// };
|
|
79
77
|
//# sourceMappingURL=prices.js.map
|
package/dist/prices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prices.js","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACpD,sDAAsG;AAItG,+EAA+E;AACxE,MAAM,qBAAqB,GAAG,CAAC,aAAgC,EAAU,EAAE;IAChF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,SAA0B,EAAE,EAAE;;QACtE,gCAAgC;QAChC,IAAI,CAAC,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,0CAAE,MAAM,CAAA,EAAE,CAAC;YACpC,OAAO,GAAG,GAAG,CAAC,CAAC;QACjB,CAAC;QACD,iCAAiC;QACjC,OAAO,GAAG,GAAG,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC;IAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;AACR,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC;AAEF,qGAAqG;AACrG,wFAAwF;AACxF,uEAAuE;AACvE,8FAA8F;AACvF,MAAM,8BAA8B,GAAG,CAC5C,+BAAuC,EACvC,KAAkB,EAClB,OAAsB,EACtB,4BAAoC,EAC2C,EAAE;IACjF,QAAQ,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAChC,KAAK,iCAAkB,CAAC,sBAAsB;YAC5C,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,OAAO,EAAE,CAAC,EAAE,iBAAiB,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,gHAAgH;QACp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GAAG,CAAC,UAAkB,EAAE,gCAAqC,EAAU,EAAE,CAC9H,UAAU,GAAG,gCAAgC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,gCAAgC,CAAC;AAD3F,QAAA,0CAA0C,8CACiD;AACxG,0FAA0F;AAC1F,iGAAiG;AACjG,gIAAgI;AAChI,6CAA6C;AAC7C,yHAAyH;AACzH,4BAA4B;AAC5B,6BAA6B;AAC7B,iDAAiD;AACjD,aAAa;AACb,mHAAmH;AACnH,SAAS;AACT,MAAM;AAEN,wHAAwH;AACxH,0CAA0C;AAC1C,mBAAmB;AACnB,MAAM;AAEN,0BAA0B;AAC1B,qHAAqH;AACrH,yCAAyC;AACzC,qBAAqB;AACrB,QAAQ;AACR,MAAM;AAEN,kBAAkB;AAClB,KAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimee/calculations",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "nimi calculations like prices for back and front",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "dan goldberg",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
14
14
|
"incVersionAndPublish": "npm version patch && npm run publish-it && npm run i-all-workspaces",
|
|
15
15
|
"publish-it": "npm run build && npm publish --scope=nimee --access public",
|
|
16
|
-
"i-all-workspaces": "version=${npm_package_version} npm i @nimee/calculations@$version --workspace=@nimee/event --workspace=@nimee/user-event --workspace=@nimee/send-notification --workspace=@nimee/user --workspace=@nimee/payment --workspace=@nimee/analytics"
|
|
16
|
+
"i-all-workspaces": "version=${npm_package_version} npm i @nimee/calculations@$version --workspace=@nimee/event --workspace=@nimee/user-event --workspace=@nimee/send-notification --workspace=@nimee/user --workspace=@nimee/payment --workspace=@nimee/analytics --workspace=@nimee/crm"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
package/src/prices.ts
CHANGED
|
@@ -29,7 +29,11 @@ export const calculateFinalPriceWithNimiFee = (
|
|
|
29
29
|
case IFeeCollectionType.PERCENTAGE_FROM_TICKET:
|
|
30
30
|
return { finalPriceWithNimiFee: totalPriceWithCouponDiscount, nimiFee: 0, nimiFeePercentage: account.marketFee }; // we use here marketFee (and not originalMarketFee) because we need to send the fee to payme without their fee
|
|
31
31
|
case IFeeCollectionType.ON_TOP_OF_TICKET:
|
|
32
|
-
//
|
|
32
|
+
// check if the totalPrice with coupon discount is 0 then we return 0 for the fee and the percentage
|
|
33
|
+
if (totalPriceWithCouponDiscount === 0) {
|
|
34
|
+
return { finalPriceWithNimiFee: 0, nimiFee: 0, nimiFeePercentage: 0 };
|
|
35
|
+
}
|
|
36
|
+
// minimum 3 so we use max we totalPriceWithoutCouponDiscount because the fee is calculated on top of the original price and not the price after discount
|
|
33
37
|
const unroundedFee = Math.max(3, (totalPriceWithoutCouponDiscount * account.originalMarketFee) / 100); // here we use originalMarketFee because we need to calculate the fee on top of the original price (later we will subtract payme fee from the fee we send to payme)
|
|
34
38
|
const roundedFee = Math.round(unroundedFee);
|
|
35
39
|
// nimiFeePercentage has unknown range that need to be aware of - we get error when we send to payme with range above 60 so we use max
|
|
@@ -47,31 +51,32 @@ export const calculateFinalPriceWithNimiFee = (
|
|
|
47
51
|
};
|
|
48
52
|
export const calculateFinalPriceWithCouponDiscount = (totalPrice: number, couponDiscount: number): number =>
|
|
49
53
|
totalPrice - couponDiscount < 0 ? 0 : totalPrice - couponDiscount;
|
|
50
|
-
|
|
54
|
+
export const calculateFinalPriceWithEndUserSeasonTicket = (totalPrice: number, endUserSeasonTicketDiscountPrice: any): number =>
|
|
55
|
+
totalPrice - endUserSeasonTicketDiscountPrice < 0 ? 0 : totalPrice - endUserSeasonTicketDiscountPrice;
|
|
51
56
|
// Validate the order is really free, rather the tickets free or with the coupon discount.
|
|
52
57
|
// we do this so the client won't be able to create orders with price 0 and it won't be validated
|
|
53
|
-
export const validateFreeOrder = async (ticketIds: string[], couponDiscount: number, accountId: string, eventId: string) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
// export const validateFreeOrder = async (ticketIds: string[], couponDiscount: number, accountId: string, eventId: string) => {
|
|
59
|
+
// const ticketClient = new TicketClient();
|
|
60
|
+
// const tickets = await ticketClient.getTicketsByIds({ token: process.env.JWT_ADMIN, ticketIds, accountId, eventId });
|
|
61
|
+
// if (!tickets?.length) {
|
|
62
|
+
// throw new CustomError(
|
|
63
|
+
// "tickets_not_found_validate_free_order",
|
|
64
|
+
// 400,
|
|
65
|
+
// `tickets not found when try to validate free order with ticketIds - ${ticketIds} and eventId - ${eventId}`
|
|
66
|
+
// );
|
|
67
|
+
// }
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
// const rawOrderPriceFromTickets = tickets.reduce((acc: number, ticket: { price: number }) => acc + ticket.price, 0);
|
|
70
|
+
// if (rawOrderPriceFromTickets === 0) {
|
|
71
|
+
// return true;
|
|
72
|
+
// }
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
// if (couponDiscount) {
|
|
75
|
+
// const orderPriceAfterCoupon = calculateFinalPriceWithCouponDiscount(rawOrderPriceFromTickets, couponDiscount);
|
|
76
|
+
// if (orderPriceAfterCoupon === 0) {
|
|
77
|
+
// return true;
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
};
|
|
81
|
+
// return false;
|
|
82
|
+
// };
|