@bash-app/bash-common 2.0.0 → 3.0.0
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/package.json +1 -1
- package/prisma/schema.prisma +4 -4
- package/src/definitions.ts +1 -0
- package/src/utils/paymentUtils.ts +23 -3
package/package.json
CHANGED
package/prisma/schema.prisma
CHANGED
|
@@ -157,12 +157,12 @@ model BashEventPromoCode {
|
|
|
157
157
|
bashEventId String
|
|
158
158
|
bashEvent BashEvent @relation(fields: [bashEventId], references: [id], onDelete: Cascade)
|
|
159
159
|
code String
|
|
160
|
-
|
|
160
|
+
stripeCouponId String?
|
|
161
161
|
discountAmountInCents Int?
|
|
162
|
-
discountAmountPercentage
|
|
162
|
+
discountAmountPercentage Int?
|
|
163
|
+
maxRedemptions Int?
|
|
164
|
+
redeemBy DateTime?
|
|
163
165
|
usedBy User[]
|
|
164
|
-
validStartDateTime DateTime @default(now())
|
|
165
|
-
validUntilDateTime DateTime?
|
|
166
166
|
|
|
167
167
|
@@unique([bashEventId, code])
|
|
168
168
|
}
|
package/src/definitions.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import {TicketTier} from "@prisma/client";
|
|
1
|
+
import {BashEventPromoCode, TicketTier} from "@prisma/client";
|
|
2
2
|
import {BASH_FEE_PERCENTAGE, NumberOfTicketsForDate, PRICE_DOLLARS_AND_CENTS_RATIO} from "../definitions";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns the amount of discount in dollars
|
|
7
|
+
* @param totalInDollars
|
|
8
|
+
* @param promoCode
|
|
9
|
+
*/
|
|
10
|
+
export function calculateDiscountFromPromoCode(totalInDollars: number, promoCode: BashEventPromoCode | undefined): number {
|
|
11
|
+
if (promoCode) {
|
|
12
|
+
if (promoCode.discountAmountInCents) {
|
|
13
|
+
const discountInDollars = convertCentsToDollars(promoCode.discountAmountInCents);
|
|
14
|
+
return Math.max(0, discountInDollars); // Ensure we don't discount more than 100%
|
|
15
|
+
}
|
|
16
|
+
if (promoCode.discountAmountPercentage) {
|
|
17
|
+
const discountInDollars = totalInDollars * (promoCode.discountAmountPercentage / 100);
|
|
18
|
+
return Math.min(totalInDollars, discountInDollars); // Ensure we don't discount more than 100%
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
5
25
|
/**
|
|
6
26
|
* Returns the total price based on a map where the keys are the ticketTierIds
|
|
7
27
|
* @param ticketTiers
|
|
@@ -18,13 +38,13 @@ export function calculateTotalPriceWithoutTax(ticketTiers: TicketTier[], ticketL
|
|
|
18
38
|
return total;
|
|
19
39
|
}
|
|
20
40
|
|
|
21
|
-
export function convertCentsToDollars(price: number | undefined): number {
|
|
41
|
+
export function convertCentsToDollars(price: number | undefined | null): number {
|
|
22
42
|
if (!price) {
|
|
23
43
|
return 0;
|
|
24
44
|
}
|
|
25
45
|
return price / PRICE_DOLLARS_AND_CENTS_RATIO;
|
|
26
46
|
}
|
|
27
|
-
export function convertDollarsToCents(price: number | undefined): number {
|
|
47
|
+
export function convertDollarsToCents(price: number | undefined | null): number {
|
|
28
48
|
if (!price) {
|
|
29
49
|
return 0;
|
|
30
50
|
}
|