@bash-app/bash-common 30.96.0 → 30.97.1
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/definitions.d.ts +5 -2
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +3 -2
- package/dist/definitions.js.map +1 -1
- package/dist/extendedSchemas.d.ts +257 -1
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js +22 -0
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/bashCashPaymentUtils.d.ts +72 -0
- package/dist/utils/bashCashPaymentUtils.d.ts.map +1 -0
- package/dist/utils/bashCashPaymentUtils.js +115 -0
- package/dist/utils/bashCashPaymentUtils.js.map +1 -0
- package/dist/utils/service/apiServiceBookingApiUtils.d.ts.map +1 -1
- package/dist/utils/service/apiServiceBookingApiUtils.js +1 -0
- package/dist/utils/service/apiServiceBookingApiUtils.js.map +1 -1
- package/dist/utils/service/frontendServiceBookingUtils.d.ts +1 -0
- package/dist/utils/service/frontendServiceBookingUtils.d.ts.map +1 -1
- package/dist/utils/service/frontendServiceBookingUtils.js +1 -0
- package/dist/utils/service/frontendServiceBookingUtils.js.map +1 -1
- package/package.json +1 -1
- package/prisma/MIGRATION-CHECKLIST.md +198 -0
- package/prisma/manual-migration-add-missing-columns.sql +182 -0
- package/prisma/quick-migration.sql +47 -0
- package/prisma/schema.prisma +177 -66
- package/src/definitions.ts +6 -1
- package/src/extendedSchemas.ts +40 -0
- package/src/index.ts +1 -0
- package/src/utils/bashCashPaymentUtils.ts +146 -0
- package/src/utils/service/apiServiceBookingApiUtils.ts +1 -0
- package/src/utils/service/frontendServiceBookingUtils.ts +2 -0
package/src/extendedSchemas.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
BlogPost,
|
|
11
11
|
BlogTag,
|
|
12
12
|
Checkout,
|
|
13
|
+
Competition,
|
|
13
14
|
Contact,
|
|
14
15
|
Coordinates,
|
|
15
16
|
Demerit,
|
|
@@ -23,11 +24,13 @@ import {
|
|
|
23
24
|
Notification,
|
|
24
25
|
Organization,
|
|
25
26
|
Prisma,
|
|
27
|
+
Prize,
|
|
26
28
|
Recurrence,
|
|
27
29
|
Reminder,
|
|
28
30
|
Review,
|
|
29
31
|
Service,
|
|
30
32
|
ServiceAddon,
|
|
33
|
+
TaskComment,
|
|
31
34
|
ServiceBooking,
|
|
32
35
|
ServiceBookingAddOn,
|
|
33
36
|
ServiceBookingCheckout,
|
|
@@ -153,6 +156,14 @@ export const PRIVATE_USER_ACCOUNT_TO_SELECT = {
|
|
|
153
156
|
|
|
154
157
|
export interface SponsoredEventExt extends SponsoredEvent {}
|
|
155
158
|
|
|
159
|
+
export interface PrizeExt extends Prize {
|
|
160
|
+
winner?: PublicUser | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface CompetitionExt extends Competition {
|
|
164
|
+
prizes: PrizeExt[];
|
|
165
|
+
}
|
|
166
|
+
|
|
156
167
|
export interface BashEventExt extends BashEvent {
|
|
157
168
|
targetAudience?: TargetAudience;
|
|
158
169
|
amountOfGuests?: AmountOfGuests;
|
|
@@ -168,6 +179,7 @@ export interface BashEventExt extends BashEvent {
|
|
|
168
179
|
venueServiceId?: string;
|
|
169
180
|
venueOwner?: PublicUser;
|
|
170
181
|
sponsorships?: SponsoredEventExt[];
|
|
182
|
+
competitions?: CompetitionExt[];
|
|
171
183
|
}
|
|
172
184
|
|
|
173
185
|
export const TICKET_TIER_DATA_TO_INCLUDE = {
|
|
@@ -205,6 +217,17 @@ export const BASH_EVENT_DATA_TO_INCLUDE = {
|
|
|
205
217
|
media: true,
|
|
206
218
|
eventTasks: true,
|
|
207
219
|
invitations: true,
|
|
220
|
+
competitions: {
|
|
221
|
+
include: {
|
|
222
|
+
prizes: {
|
|
223
|
+
include: {
|
|
224
|
+
winner: {
|
|
225
|
+
select: FRONT_END_USER_DATA_TO_SELECT,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
208
231
|
} satisfies Prisma.BashEventInclude;
|
|
209
232
|
|
|
210
233
|
export const BASH_EVENT_DATA_TO_CLONE = [
|
|
@@ -741,9 +764,20 @@ export const BASH_NOTIFICATION_DATA_TO_INCLUDE = {
|
|
|
741
764
|
},
|
|
742
765
|
} satisfies Prisma.NotificationInclude;
|
|
743
766
|
|
|
767
|
+
export interface TaskCommentExt extends TaskComment {
|
|
768
|
+
author: PublicUser;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export const TASK_COMMENT_DATA_TO_INCLUDE = {
|
|
772
|
+
author: {
|
|
773
|
+
select: FRONT_END_USER_DATA_TO_SELECT,
|
|
774
|
+
},
|
|
775
|
+
} satisfies Prisma.TaskCommentInclude;
|
|
776
|
+
|
|
744
777
|
export interface EventTaskExt extends EventTask {
|
|
745
778
|
creator: PublicUser;
|
|
746
779
|
assignedTo?: PublicUser | null;
|
|
780
|
+
comments?: TaskCommentExt[];
|
|
747
781
|
}
|
|
748
782
|
|
|
749
783
|
export const EVENT_TASK_DATA_TO_INCLUDE = {
|
|
@@ -753,6 +787,12 @@ export const EVENT_TASK_DATA_TO_INCLUDE = {
|
|
|
753
787
|
assignedTo: {
|
|
754
788
|
select: FRONT_END_USER_DATA_TO_SELECT,
|
|
755
789
|
},
|
|
790
|
+
comments: {
|
|
791
|
+
include: TASK_COMMENT_DATA_TO_INCLUDE,
|
|
792
|
+
orderBy: {
|
|
793
|
+
createdAt: 'desc' as const,
|
|
794
|
+
},
|
|
795
|
+
},
|
|
756
796
|
} satisfies Prisma.EventTaskInclude;
|
|
757
797
|
|
|
758
798
|
export interface InvitationExt extends Invitation {
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./utils/addressUtils";
|
|
|
5
5
|
export * from "./utils/apiUtils";
|
|
6
6
|
export * from "./utils/arrayUtils";
|
|
7
7
|
export * from "./utils/awsS3Utils";
|
|
8
|
+
export * from "./utils/bashCashPaymentUtils";
|
|
8
9
|
export * from "./utils/contentFilterUtils";
|
|
9
10
|
export * from "./utils/dateTimeUtils";
|
|
10
11
|
export * from "./utils/objUtils";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BashCash Payment Utilities
|
|
3
|
+
* Handles calculations and conversions for BashCash payment system
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// 1 BashCash credit = 1 cent = $0.01
|
|
7
|
+
export const BASHCASH_TO_CENTS_RATE = 1;
|
|
8
|
+
export const CENTS_TO_BASHCASH_RATE = 1;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convert USD cents to BashCash credits
|
|
12
|
+
* @param cents Amount in cents (e.g., 28750 = $287.50)
|
|
13
|
+
* @returns BashCash credits (e.g., 28750 credits)
|
|
14
|
+
*/
|
|
15
|
+
export function centsToBashCash(cents: number): number {
|
|
16
|
+
return Math.floor(cents * CENTS_TO_BASHCASH_RATE);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Convert BashCash credits to USD cents
|
|
21
|
+
* @param credits BashCash credits (e.g., 28750 credits)
|
|
22
|
+
* @returns Amount in cents (e.g., 28750 = $287.50)
|
|
23
|
+
*/
|
|
24
|
+
export function bashCashToCents(credits: number): number {
|
|
25
|
+
return Math.floor(credits * BASHCASH_TO_CENTS_RATE);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Format BashCash credits for display
|
|
30
|
+
* @param credits BashCash credits
|
|
31
|
+
* @returns Formatted string (e.g., "28,750 credits")
|
|
32
|
+
*/
|
|
33
|
+
export function formatBashCash(credits: number): string {
|
|
34
|
+
return `${credits.toLocaleString('en-US')} credit${credits === 1 ? '' : 's'}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Format BashCash credits with USD equivalent
|
|
39
|
+
* @param credits BashCash credits
|
|
40
|
+
* @returns Formatted string (e.g., "28,750 credits ($287.50)")
|
|
41
|
+
*/
|
|
42
|
+
export function formatBashCashWithUSD(credits: number): string {
|
|
43
|
+
const cents = bashCashToCents(credits);
|
|
44
|
+
const dollars = (cents / 100).toFixed(2);
|
|
45
|
+
return `${formatBashCash(credits)} ($${dollars})`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Calculate maximum BashCash that can be used for a booking
|
|
50
|
+
* @param totalCents Total booking cost in cents
|
|
51
|
+
* @param userBalance User's BashCash balance in credits
|
|
52
|
+
* @returns Maximum BashCash credits that can be applied
|
|
53
|
+
*/
|
|
54
|
+
export function calculateMaxBashCashForBooking(
|
|
55
|
+
totalCents: number,
|
|
56
|
+
userBalance: number
|
|
57
|
+
): number {
|
|
58
|
+
// No cap on BashCash usage for service bookings (can pay 100% if they have enough)
|
|
59
|
+
const maxPossible = centsToBashCash(totalCents);
|
|
60
|
+
return Math.min(maxPossible, userBalance);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Calculate split payment amounts
|
|
65
|
+
* @param totalCents Total booking cost in cents
|
|
66
|
+
* @param bashCashToUse BashCash credits user wants to apply
|
|
67
|
+
* @returns Object with bashCashCents and stripeCents
|
|
68
|
+
*/
|
|
69
|
+
export function calculateSplitPayment(
|
|
70
|
+
totalCents: number,
|
|
71
|
+
bashCashToUse: number
|
|
72
|
+
): {
|
|
73
|
+
bashCashCents: number;
|
|
74
|
+
stripeCents: number;
|
|
75
|
+
bashCashCredits: number;
|
|
76
|
+
} {
|
|
77
|
+
const bashCashCents = bashCashToCents(bashCashToUse);
|
|
78
|
+
const stripeCents = Math.max(0, totalCents - bashCashCents);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
bashCashCents,
|
|
82
|
+
stripeCents,
|
|
83
|
+
bashCashCredits: bashCashToUse,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Validate BashCash payment
|
|
89
|
+
* @param bashCashToUse BashCash credits to use
|
|
90
|
+
* @param userBalance User's current balance
|
|
91
|
+
* @param totalCents Total booking cost
|
|
92
|
+
* @returns Validation result
|
|
93
|
+
*/
|
|
94
|
+
export function validateBashCashPayment(
|
|
95
|
+
bashCashToUse: number,
|
|
96
|
+
userBalance: number,
|
|
97
|
+
totalCents: number
|
|
98
|
+
): {
|
|
99
|
+
valid: boolean;
|
|
100
|
+
errorMessage?: string;
|
|
101
|
+
} {
|
|
102
|
+
if (bashCashToUse < 0) {
|
|
103
|
+
return {
|
|
104
|
+
valid: false,
|
|
105
|
+
errorMessage: "BashCash amount cannot be negative",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (bashCashToUse > userBalance) {
|
|
110
|
+
return {
|
|
111
|
+
valid: false,
|
|
112
|
+
errorMessage: `Insufficient BashCash balance. You have ${formatBashCash(userBalance)}, but tried to use ${formatBashCash(bashCashToUse)}.`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const bashCashCents = bashCashToCents(bashCashToUse);
|
|
117
|
+
if (bashCashCents > totalCents) {
|
|
118
|
+
return {
|
|
119
|
+
valid: false,
|
|
120
|
+
errorMessage: `BashCash amount ($${(bashCashCents / 100).toFixed(2)}) exceeds booking total ($${(totalCents / 100).toFixed(2)}).`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { valid: true };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Calculate BashCash cashback for a service booking (3%)
|
|
129
|
+
* @param amountCents Amount paid in cents
|
|
130
|
+
* @returns BashCash credits earned as cashback
|
|
131
|
+
*/
|
|
132
|
+
export function calculateServiceBookingCashback(amountCents: number): number {
|
|
133
|
+
const CASHBACK_RATE = 0.03; // 3% for service bookings
|
|
134
|
+
return Math.floor((amountCents * CASHBACK_RATE));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Calculate BashCash cashback for a ticket purchase (5%)
|
|
139
|
+
* @param amountCents Amount paid in cents
|
|
140
|
+
* @returns BashCash credits earned as cashback
|
|
141
|
+
*/
|
|
142
|
+
export function calculateTicketCashback(amountCents: number): number {
|
|
143
|
+
const CASHBACK_RATE = 0.05; // 5% for ticket purchases
|
|
144
|
+
return Math.floor((amountCents * CASHBACK_RATE));
|
|
145
|
+
}
|
|
146
|
+
|
|
@@ -167,6 +167,7 @@ export function serviceGetPriceToBookFromBooking(
|
|
|
167
167
|
daysTotalBeforeTaxesCents: booking.daysTotalATBCents,
|
|
168
168
|
subtotalBeforeTaxesCents: booking.subtotalATBCents,
|
|
169
169
|
totalBeforeTaxesCents: booking.totalATBCents,
|
|
170
|
+
totalWithFees: booking.totalATBCents, // Same as totalATBCents
|
|
170
171
|
} as FrontendServiceGetPriceToBookResult;
|
|
171
172
|
}
|
|
172
173
|
|
|
@@ -77,6 +77,7 @@ export interface FrontendServiceGetPriceToBookResult {
|
|
|
77
77
|
daysTotalBeforeTaxesCents: number;
|
|
78
78
|
subtotalBeforeTaxesCents: number; //sum of all daysTotalBeforeTaxesCents, plus addOns/packages
|
|
79
79
|
totalBeforeTaxesCents: number;
|
|
80
|
+
totalWithFees: number; // Total including all fees (same as totalBeforeTaxesCents, kept for compatibility)
|
|
80
81
|
|
|
81
82
|
minimumTimeBlockHours?: number; //only valid on generalRate
|
|
82
83
|
}
|
|
@@ -317,6 +318,7 @@ export function frontendServiceGetPriceToBookFees(
|
|
|
317
318
|
daysTotalBeforeTaxesCents: daysTotalBeforeTaxesCents,
|
|
318
319
|
subtotalBeforeTaxesCents: subtotalBeforeTaxesCents,
|
|
319
320
|
totalBeforeTaxesCents: totalBeforeTaxesCents,
|
|
321
|
+
totalWithFees: totalBeforeTaxesCents, // Same as totalBeforeTaxesCents
|
|
320
322
|
additionalFees: allAdditionalFees,
|
|
321
323
|
addOns: usedAddons,
|
|
322
324
|
minimumTimeBlockHours: minimumTimeBlockHours,
|