@bash-app/bash-common 30.2.0 → 30.4.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.
@@ -21,7 +21,6 @@ import {
21
21
  ServiceLink,
22
22
  Link,
23
23
  Venue,
24
- // Availability,
25
24
  TargetAudience,
26
25
  Vendor,
27
26
  EventService,
@@ -33,12 +32,7 @@ import {
33
32
  Prisma,
34
33
  ServiceRange,
35
34
  StripeAccount,
36
- VisibilityPreference,
37
- BashEventType,
38
35
  Coordinates,
39
- // Rate,
40
- GoogleReview,
41
- ServiceTypes,
42
36
  ServiceRatesAssociation,
43
37
  ServiceRate,
44
38
  ServiceDailyRates,
@@ -54,6 +48,8 @@ import {
54
48
  ServiceBookingPackage,
55
49
  ServiceBookingCheckout,
56
50
  ServiceBooking,
51
+ ServiceBookingPriceBreakdown,
52
+ ServiceBookingFee,
57
53
  } from "@prisma/client";
58
54
  import { SERVICE_LINK_DATA_TO_INCLUDE } from "./definitions";
59
55
  import { serviceKeysArray } from "./utils/service/serviceUtils";
@@ -198,6 +194,23 @@ export const BASH_EVENT_DATA_TO_REMOVE: RemoveCommonProperties<
198
194
  >[] = ["creator", "eventTasks", "tickets", "targetAudience", "amountOfGuests"];
199
195
 
200
196
  //---------------Services------------------
197
+ export const PUBLIC_STRIPE_ACCOUNT_DATA_TO_SELECT = {
198
+ logo: true,
199
+ logoId: true,
200
+ createdAt: true,
201
+ updatedAt: true,
202
+ } satisfies Prisma.StripeAccountSelect;
203
+
204
+ export const STRIPE_ACCOUNT_DATA_TO_INCLUDE = {
205
+ logo: true,
206
+ owner: {
207
+ select: FRONT_END_USER_DATA_TO_SELECT,
208
+ },
209
+ userSubscription: {
210
+ select: PRIVATE_USER_SUBSCRIPTION_DATA_TO_SELECT,
211
+ },
212
+ } satisfies Prisma.StripeAccountInclude;
213
+
201
214
  export const SERVICE_PACKAGE_DATA_TO_INCLUDE = {
202
215
  serviceAddons: true,
203
216
  } satisfies Prisma.ServicePackageInclude;
@@ -225,6 +238,79 @@ export const SERVICE_RATES_ASSOCIATION_DATA_TO_INCLUDE = {
225
238
  media: true,
226
239
  } satisfies Prisma.ServiceRatesAssociationInclude;
227
240
 
241
+ export const SERVICE_DATA_TO_INCLUDE = {
242
+ creator: {
243
+ select: FRONT_END_USER_DATA_TO_SELECT,
244
+ },
245
+ owner: {
246
+ select: FRONT_END_USER_DATA_TO_SELECT,
247
+ },
248
+ targetAudience: true,
249
+ media: true,
250
+ stripeAccount: {
251
+ // ...STRIPE_ACCOUNT_DATA_TO_INCLUDE,
252
+ select: PUBLIC_STRIPE_ACCOUNT_DATA_TO_SELECT,
253
+ },
254
+ serviceLinks: {
255
+ include: SERVICE_LINK_DATA_TO_INCLUDE,
256
+ },
257
+ serviceRatesAssociation: {
258
+ include: SERVICE_RATES_ASSOCIATION_DATA_TO_INCLUDE,
259
+ },
260
+ // bookings: {
261
+ // include: SERVICE_BOOKING_PRIVATE_DATA_TO_INCLUDE, //make sure only to include owned bookedDays
262
+ // },
263
+ bashEvent: {
264
+ include: BASH_EVENT_DATA_TO_INCLUDE,
265
+ },
266
+ // bookedCheckouts: {
267
+ // include: SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE, //make sure only to include owned checkouts
268
+ // },
269
+ } satisfies Prisma.ServiceInclude;
270
+
271
+ //full service data to include, includes specific service data
272
+ export const SERVICE_FULL_DATA_TO_INCLUDE = {
273
+ ...SERVICE_DATA_TO_INCLUDE,
274
+ ...createAllTrueObject(serviceKeysArray),
275
+ } satisfies Prisma.ServiceInclude;
276
+
277
+ export const SERVICE_FULL_DATA_TO_CLONE = [
278
+ "media",
279
+ "targetAudience",
280
+ "serviceLinks",
281
+ // ...Object.values(specificServiceMap)
282
+ ] as const;
283
+
284
+ type ServiceExtMinusDataToCloneType = Omit<
285
+ ServiceExt,
286
+ UnionFromArray<typeof SERVICE_FULL_DATA_TO_CLONE>
287
+ >;
288
+ export const SERVICE_FULL_DATA_TO_REMOVE: RemoveCommonProperties<
289
+ Service,
290
+ ServiceExtMinusDataToCloneType
291
+ >[] = [
292
+ "creator",
293
+ "owner",
294
+ // "bookings"
295
+ ] as const;
296
+
297
+ export interface StripeAccountExt extends StripeAccount {
298
+ logo?: Media | null;
299
+ }
300
+
301
+ export const VENUE_DATA_TO_CLONE = [] as const;
302
+
303
+ type VenueExtMinusDataToCloneType = Omit<
304
+ Venue,
305
+ UnionFromArray<typeof VENUE_DATA_TO_CLONE>
306
+ >;
307
+ export const VENUE_DATA_TO_REMOVE: RemoveCommonProperties<
308
+ Venue,
309
+ VenueExtMinusDataToCloneType
310
+ >[] = [
311
+ // 'bashEvents',
312
+ ] as const;
313
+
228
314
  export interface ServiceRateExt extends ServiceRate {
229
315
  serviceSpecialRates?: ServiceSpecialRates;
230
316
  serviceDailyRates?: ServiceDailyRates;
@@ -260,28 +346,35 @@ export interface ServiceBookingAddOnExt extends ServiceBookingAddOn {
260
346
  export interface ServiceBookingPackageExt extends ServiceBookingPackage {
261
347
  package: ServicePackageExt;
262
348
  }
349
+ export interface ServiceBookingPriceBreakdownExt
350
+ extends ServiceBookingPriceBreakdown {}
351
+
352
+ export interface ServiceBookingFeeExt extends ServiceBookingFee {}
263
353
  export interface ServiceBookingDayExt extends ServiceBookingDay {
264
354
  // service: ServiceExt; //we don't need service here
265
355
  addOns: ServiceBookingAddOnExt[];
266
356
  packages: ServiceBookingPackageExt[];
357
+ priceBreakdown: ServiceBookingPriceBreakdownExt[];
358
+ fees: ServiceBookingFeeExt[];
267
359
  }
268
360
 
269
361
  export interface ServiceBookingExt extends ServiceBooking {
270
- // service: ServiceExt; //we don't need service here
271
362
  bookedDays: ServiceBookingDayExt[];
272
- checkout?: ServiceBookingCheckout | null;
363
+ additionalFees: ServiceBookingFeeExt[];
364
+
273
365
  creator: PublicUser;
274
366
  forUser: PublicUser;
275
- }
367
+ service: ServiceExt;
276
368
 
277
- export type ServiceBookingPublicExt = Omit<ServiceBookingExt, "checkout">;
369
+ checkout?: ServiceBookingCheckout | null;
370
+ }
278
371
 
279
372
  export interface ServiceBookingCheckoutExt extends ServiceBookingCheckout {
280
- // service: ServiceExt; //we don't need service here
281
373
  creator: PublicUser;
282
- // bookingData: ServiceBookingExt;
283
374
  }
284
375
 
376
+ export type ServiceBookingPublicExt = Omit<ServiceBookingExt, "checkout">;
377
+
285
378
  export const SERVICE_BOOKING_ADDON_DATA_TO_INCLUDE = {
286
379
  addOn: true,
287
380
  } satisfies Prisma.ServiceBookingAddOnInclude;
@@ -299,6 +392,8 @@ export const SERVICE_BOOKING_DAY_DATA_TO_INCLUDE = {
299
392
  packages: {
300
393
  include: SERVICE_BOOKING_PACKAGE_DATA_TO_INCLUDE,
301
394
  },
395
+ priceBreakdown: true,
396
+ fees: true,
302
397
  } satisfies Prisma.ServiceBookingDayInclude;
303
398
 
304
399
  export const SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE = {
@@ -313,10 +408,12 @@ export const SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE = {
313
408
  export const FRONT_END_SERVICE_BOOKING_CHECKOUT_DATA_SELECT = {
314
409
  id: true,
315
410
  creatorId: true,
316
- creator: true,
411
+ creator: {
412
+ select: FRONT_END_USER_DATA_TO_SELECT,
413
+ },
317
414
  checkoutDateTime: true,
318
- totalAmount: true,
319
- depositAmount: true,
415
+ totalAmountCents: true,
416
+ depositAmountCents: true,
320
417
  paidOn: true,
321
418
  refundedOn: true,
322
419
  } satisfies Prisma.ServiceBookingCheckoutSelect;
@@ -325,13 +422,20 @@ export const SERVICE_BOOKING_PUBLIC_DATA_TO_INCLUDE = {
325
422
  bookedDays: {
326
423
  include: SERVICE_BOOKING_DAY_DATA_TO_INCLUDE,
327
424
  },
425
+ service: {
426
+ include: {
427
+ ...SERVICE_DATA_TO_INCLUDE,
428
+ bashEvent: undefined, // Remove circular reference
429
+ },
430
+ },
431
+ additionalFees: true,
328
432
  } satisfies Prisma.ServiceBookingInclude;
329
433
 
330
434
  export const SERVICE_BOOKING_PRIVATE_DATA_TO_INCLUDE = {
331
435
  ...SERVICE_BOOKING_PUBLIC_DATA_TO_INCLUDE,
332
436
  checkout: {
333
- // select: FRONT_END_SERVICE_BOOKING_CHECKOUT_DATA_SELECT,
334
- include: SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE,
437
+ select: FRONT_END_SERVICE_BOOKING_CHECKOUT_DATA_SELECT,
438
+ // include: SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE,
335
439
  },
336
440
  creator: {
337
441
  select: FRONT_END_USER_DATA_TO_SELECT,
@@ -373,7 +477,7 @@ export interface ServiceExt extends Service {
373
477
  // googleReviews: GoogleReview[];
374
478
 
375
479
  // bookedCheckouts: ServiceBookingCheckoutExt[]; //not necessary to include
376
- bookings?: ServiceBookingExt[];
480
+ // bookings?: ServiceBookingExt[];
377
481
  }
378
482
  export interface EventServiceExt extends EventService {
379
483
  service: ServiceExt;
@@ -427,92 +531,6 @@ export interface ServiceLinkExt extends ServiceLink {
427
531
  link: Link;
428
532
  }
429
533
 
430
- //------------Stripe Accounts--------------
431
- export const PUBLIC_STRIPE_ACCOUNT_DATA_TO_SELECT = {
432
- logo: true,
433
- logoId: true,
434
- createdAt: true,
435
- updatedAt: true,
436
- } satisfies Prisma.StripeAccountSelect;
437
-
438
- export const STRIPE_ACCOUNT_DATA_TO_INCLUDE = {
439
- logo: true,
440
- owner: {
441
- select: FRONT_END_USER_DATA_TO_SELECT,
442
- },
443
- userSubscription: {
444
- select: PRIVATE_USER_SUBSCRIPTION_DATA_TO_SELECT,
445
- },
446
- } satisfies Prisma.StripeAccountInclude;
447
-
448
- export interface StripeAccountExt extends StripeAccount {
449
- logo?: Media | null;
450
- }
451
-
452
- export const SERVICE_DATA_TO_INCLUDE = {
453
- creator: {
454
- select: FRONT_END_USER_DATA_TO_SELECT,
455
- },
456
- owner: {
457
- select: FRONT_END_USER_DATA_TO_SELECT,
458
- },
459
- targetAudience: true,
460
- media: true,
461
- stripeAccount: {
462
- // ...STRIPE_ACCOUNT_DATA_TO_INCLUDE,
463
- select: PUBLIC_STRIPE_ACCOUNT_DATA_TO_SELECT,
464
- },
465
- serviceLinks: {
466
- include: SERVICE_LINK_DATA_TO_INCLUDE,
467
- },
468
- serviceRatesAssociation: {
469
- include: SERVICE_RATES_ASSOCIATION_DATA_TO_INCLUDE,
470
- },
471
- // bookings: {
472
- // include: SERVICE_BOOKING_PRIVATE_DATA_TO_INCLUDE, //make sure only to include owned bookedDays
473
- // },
474
- bashEvent: {
475
- include: BASH_EVENT_DATA_TO_INCLUDE,
476
- },
477
- // bookedCheckouts: {
478
- // include: SERVICE_BOOKING_CHECKOUT_DATA_TO_INCLUDE, //make sure only to include owned checkouts
479
- // },
480
- } satisfies Prisma.ServiceInclude;
481
-
482
- //full service data to include, includes specific service data
483
- export const SERVICE_FULL_DATA_TO_INCLUDE = {
484
- ...SERVICE_DATA_TO_INCLUDE,
485
- ...createAllTrueObject(serviceKeysArray),
486
- } satisfies Prisma.ServiceInclude;
487
-
488
- export const SERVICE_FULL_DATA_TO_CLONE = [
489
- "media",
490
- "targetAudience",
491
- "serviceLinks",
492
- // ...Object.values(specificServiceMap)
493
- ] as const;
494
-
495
- type ServiceExtMinusDataToCloneType = Omit<
496
- ServiceExt,
497
- UnionFromArray<typeof SERVICE_FULL_DATA_TO_CLONE>
498
- >;
499
- export const SERVICE_FULL_DATA_TO_REMOVE: RemoveCommonProperties<
500
- Service,
501
- ServiceExtMinusDataToCloneType
502
- >[] = ["creator", "owner", "bookings"] as const;
503
-
504
- export const VENUE_DATA_TO_CLONE = [] as const;
505
-
506
- type VenueExtMinusDataToCloneType = Omit<
507
- Venue,
508
- UnionFromArray<typeof VENUE_DATA_TO_CLONE>
509
- >;
510
- export const VENUE_DATA_TO_REMOVE: RemoveCommonProperties<
511
- Venue,
512
- VenueExtMinusDataToCloneType
513
- >[] = [
514
- // 'bashEvents',
515
- ] as const;
516
534
  //-----------------------------------------
517
535
 
518
536
  export interface BashNotificationExt extends BashNotification {
package/src/index.ts CHANGED
@@ -11,17 +11,18 @@ export * from "./utils/sortUtils";
11
11
  export * from "./utils/apiUtils";
12
12
  export * from "./utils/urlUtils";
13
13
  export * from "./utils/stringUtils";
14
+ export * from "./utils/arrayUtils";
14
15
  export * from "./utils/promoCodesUtils";
15
16
  export * from "./utils/userPromoCodeUtils";
16
17
  export * from "./utils/userSubscriptionUtils";
17
18
  export * from "./utils/service/serviceUtils";
18
19
  export * from "./utils/service/venueUtils";
19
20
  export * from "./utils/service/attendeeOptionUtils";
20
- export * from "./utils/service/serviceRateDBUtils";
21
+ // export * from "./utils/service/serviceRateDBUtils";
21
22
  export * from "./utils/service/serviceDBUtils";
22
23
  export * from "./utils/service/serviceRateUtils";
23
- export * from "./utils/service/serviceBookingUtils";
24
- export * from "./utils/service/serviceBookingApiUtils";
24
+ export * from "./utils/service/frontendServiceBookingUtils";
25
+ export * from "./utils/service/apiServiceBookingApiUtils";
25
26
  export * from "./utils/service/serviceBookingStatusUtils";
26
27
  export * from "./utils/stripeAccountUtils";
27
28
  export * from "./utils/entityUtils";
@@ -0,0 +1,8 @@
1
+ export async function asyncFilter<T>(
2
+ arr: T[],
3
+ predicate: (t: T) => Promise<boolean>
4
+ ) {
5
+ const results = await Promise.all(arr.map(predicate));
6
+
7
+ return arr.filter((_v, index) => results[index]);
8
+ }
@@ -151,7 +151,7 @@ export function dateTimeFromComponents(
151
151
  return res;
152
152
  }
153
153
 
154
- export function dateTimeGetDateTimeTIme(dateTime: DateTime) {
154
+ export function dateTimeGetDateTimeTime(dateTime: DateTime) {
155
155
  return DateTime.fromObject(
156
156
  {
157
157
  // day: dayOfWeekIdxToDay[dateTime.weekday as DayOfWeekIdx],
@@ -186,13 +186,17 @@ export function dateTimeSetDate(
186
186
 
187
187
  export function dateRangeGetDateTimeTIme(dateRange: LuxonDateRange) {
188
188
  return {
189
- start: dateTimeGetDateTimeTIme(dateRange.start),
190
- end: dateTimeGetDateTimeTIme(dateRange.end),
189
+ start: dateTimeGetDateTimeTime(dateRange.start),
190
+ end: dateTimeGetDateTimeTime(dateRange.end),
191
191
  };
192
192
  }
193
193
 
194
- export function dateTimeFormatTime(dateTime: DateTime) {
195
- return dateTime.toFormat(LUXON_TIME_FORMAT_AM_PM);
194
+ export function dateTimeFormat(dateTime?: DateTime | null) {
195
+ return dateTime?.toFormat(LUXON_DATETIME_FORMAT_STANDARD) ?? "";
196
+ }
197
+
198
+ export function dateTimeFormatTime(dateTime?: DateTime | null) {
199
+ return dateTime?.toFormat(LUXON_TIME_FORMAT_AM_PM) ?? "";
196
200
  }
197
201
 
198
202
  export function dateTimeWithinRange(
@@ -264,14 +268,36 @@ export function dateTimeFormatDateRange(
264
268
  endDateTimeArg: DateTime | null
265
269
  ): string {
266
270
  if (startDateTimeArg?.day === endDateTimeArg?.day) {
267
- return `${startDateTimeArg?.toFormat(
268
- LUXON_DATETIME_FORMAT_STANDARD
269
- )} to ${endDateTimeArg?.toFormat(LUXON_TIME_FORMAT_AM_PM)}`;
271
+ return `${dateTimeFormat(startDateTimeArg)} to ${dateTimeFormatTime(
272
+ endDateTimeArg
273
+ )}`;
274
+ }
275
+
276
+ return `${dateTimeFormat(startDateTimeArg)} to ${dateTimeFormat(
277
+ endDateTimeArg
278
+ )}`;
279
+ }
280
+
281
+ export interface DateTimeFormatDateRangeListResult {
282
+ start: string;
283
+ end: string;
284
+ }
285
+
286
+ export function dateTimeFormatDateRangeList(
287
+ startDateTimeArg: DateTime | null,
288
+ endDateTimeArg: DateTime | null
289
+ ): DateTimeFormatDateRangeListResult {
290
+ if (startDateTimeArg?.day === endDateTimeArg?.day) {
291
+ return {
292
+ start: dateTimeFormat(startDateTimeArg),
293
+ end: dateTimeFormatTime(endDateTimeArg),
294
+ };
270
295
  }
271
296
 
272
- return `${startDateTimeArg?.toFormat(
273
- LUXON_DATETIME_FORMAT_STANDARD
274
- )} to ${endDateTimeArg?.toFormat(LUXON_DATETIME_FORMAT_STANDARD)}`;
297
+ return {
298
+ start: dateTimeFormat(startDateTimeArg),
299
+ end: dateTimeFormat(endDateTimeArg),
300
+ };
275
301
  }
276
302
 
277
303
  export interface LuxonDateRange {
@@ -674,6 +700,31 @@ export interface TimeSlots {
674
700
  // } as TimeSlots;
675
701
  // }
676
702
 
703
+ // export function generateTimeSlots(filteredHours: LuxonDateRange[]): TimeSlots {
704
+ // const timeSlotsStart: string[] = [];
705
+ // let timeSlotsEnd: string[] = [];
706
+
707
+ // filteredHours.forEach(({ start, end }) => {
708
+ // let currentTime = start;
709
+
710
+ // while (currentTime < end) {
711
+ // timeSlotsStart.push(dateTimeFormatTime(currentTime)); // Add the time in "HH:mm" format
712
+ // currentTime = currentTime.plus({ minutes: 30 }); // Increment by 30 minutes
713
+ // }
714
+
715
+ // const finalTime =
716
+ // currentTime.hour == 0 && currentTime.minute == 0
717
+ // ? currentTime.set({ hour: 23, minute: 59 })
718
+ // : currentTime;
719
+ // timeSlotsEnd = [...timeSlotsStart, dateTimeFormatTime(finalTime)];
720
+ // });
721
+
722
+ // return {
723
+ // start: timeSlotsStart,
724
+ // end: timeSlotsEnd,
725
+ // } as TimeSlots;
726
+ // }
727
+
677
728
  export function generateTimeSlots(filteredHours: LuxonDateRange[]): TimeSlots {
678
729
  const timeSlotsStart: string[] = [];
679
730
  let timeSlotsEnd: string[] = [];
@@ -681,16 +732,26 @@ export function generateTimeSlots(filteredHours: LuxonDateRange[]): TimeSlots {
681
732
  filteredHours.forEach(({ start, end }) => {
682
733
  let currentTime = start;
683
734
 
684
- while (currentTime < end) {
735
+ const startEnd = start.set({ hour: 23, minute: 59 });
736
+ const endEnd = end.set({ hour: 23, minute: 59 });
737
+
738
+ while (currentTime < startEnd) {
685
739
  timeSlotsStart.push(dateTimeFormatTime(currentTime)); // Add the time in "HH:mm" format
686
740
  currentTime = currentTime.plus({ minutes: 30 }); // Increment by 30 minutes
687
741
  }
688
742
 
743
+ currentTime = end;
744
+ while (currentTime < endEnd) {
745
+ timeSlotsEnd.push(dateTimeFormatTime(currentTime)); // Add the time in "HH:mm" format
746
+ currentTime = currentTime.plus({ minutes: 30 }); // Increment by 30 minutes
747
+ }
748
+
689
749
  const finalTime =
690
750
  currentTime.hour == 0 && currentTime.minute == 0
691
751
  ? currentTime.set({ hour: 23, minute: 59 })
692
752
  : currentTime;
693
- timeSlotsEnd = [...timeSlotsStart.slice(1), dateTimeFormatTime(finalTime)];
753
+
754
+ timeSlotsEnd = [...timeSlotsEnd, dateTimeFormatTime(finalTime)];
694
755
  });
695
756
 
696
757
  return {
@@ -900,7 +961,9 @@ export function dateTimeToString(dateTime: DateTime): string | null {
900
961
  return dateTime.toISO();
901
962
  }
902
963
 
903
- export function dateRangesFormat(dateTimes: LuxonDateRange[]): string {
904
- const result = dateTimes.join(", ");
964
+ export function dateRangesFormat(dateRanges: LuxonDateRange[]): string {
965
+ const result = dateRanges
966
+ .map((dateRange) => dateTimeFormatDateRange(dateRange.start, dateRange.end))
967
+ .join(", ");
905
968
  return result;
906
969
  }