@bash-app/bash-common 12.1.0 → 12.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash-app/bash-common",
3
- "version": "12.1.0",
3
+ "version": "12.2.0",
4
4
  "description": "Common data and scripts to use on the frontend and backend",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -51,7 +51,7 @@ export const HTTP_CODE_NOT_FOUND = 404 as const;
51
51
  export const ERR_UNAUTHORIZED_REQUEST = "Unauthorized to perform requested action. Have you logged in?" as const;
52
52
 
53
53
  export const URL_PARAMS_BASH_EVENT_ID = 'bashEventId' as const;
54
- export const URL_PARAMS_BASH_EVENT_TITLE = 'bashEventId' as const;
54
+ export const URL_PARAMS_BASH_EVENT_TITLE = 'bashEventTitle' as const;
55
55
  export const URL_PARAMS_BASH_EVENT_DESC = 'bashEventDesc' as const;
56
56
  export const URL_PARAMS_BASH_EVENT_COVER_PHOTO = 'bashEventCoverPhoto' as const;
57
57
  export const URL_PARAMS_EMAIL = 'email' as const;
package/src/index.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./utils/paymentUtils";
8
8
  export * from "./utils/awsS3Utils";
9
9
  export * from "./utils/qrCodeUtils";
10
10
  export * from "./utils/sortUtils";
11
+ export * from "./utils/apiUtils";
@@ -0,0 +1,76 @@
1
+ import {BashEvent, Contact, User } from "@prisma/client";
2
+ import {ContactOrUser} from "../definitions";
3
+ import {Public_User} from "../extendedSchemas";
4
+
5
+ type CombinedUser = User | Public_User;
6
+ type CombinedUserOrContact = CombinedUser | Contact;
7
+
8
+ export function isContactAndNotUser(contactOrUser: Partial<ContactOrUser>): contactOrUser is Contact {
9
+ return !!(contactOrUser as Contact).contactOwnerId;
10
+ }
11
+
12
+ export function getUserName(contactOrUser: Partial<CombinedUserOrContact> | undefined): string {
13
+ if (!contactOrUser) {
14
+ return '';
15
+ }
16
+ if (isContactAndNotUser(contactOrUser)) {
17
+ return contactOrUser.fullName ?? (contactOrUser as Contact).contactEmail ?? '';
18
+ }
19
+ const user = contactOrUser as CombinedUser;
20
+ const combinedName = user.givenName && user.familyName ? `${user.givenName} ${user.familyName}` : null;
21
+ return combinedName ?? user.email;
22
+ }
23
+
24
+ export function getUserImage(contactOrUser: CombinedUserOrContact | undefined): string {
25
+ if (!contactOrUser) {
26
+ return '';
27
+ }
28
+ const noProfilePicture = '/noProfilePicture.svg';
29
+ if (isContactAndNotUser(contactOrUser)) {
30
+ return noProfilePicture;
31
+ }
32
+ const user = contactOrUser as CombinedUser;
33
+ return user.uploadedImage ?? user.image ?? noProfilePicture;
34
+ }
35
+
36
+ export function getContactOrUserEmail(contactOrUser: Partial<ContactOrUser>): string {
37
+ return isContactAndNotUser(contactOrUser)
38
+ ? (contactOrUser as Contact).contactEmail ?? ''
39
+ : (contactOrUser as User).email;
40
+ }
41
+
42
+ export function getUserIdAndNotContactId(contactOrUser: Partial<ContactOrUser>): string | null {
43
+ return isContactAndNotUser(contactOrUser)
44
+ ? null
45
+ : (contactOrUser as User).id;
46
+ }
47
+
48
+ export function getBashEventDetailUrlParamsFromBashEvent(bashEvent: BashEvent | undefined, coverPhoto?: string): string {
49
+ if (!bashEvent) {
50
+ return '';
51
+ }
52
+ return getBashEventDetailUrlParams(bashEvent.title, bashEvent.description, coverPhoto ?? bashEvent.coverPhoto);
53
+ }
54
+
55
+ function getBashEventDetailUrlParams(bashEventTitle: string | undefined,
56
+ bashEventDescription: string | undefined | null,
57
+ coverPhoto?: string | null): string {
58
+ // Don't let the description be huge
59
+ const desc = bashEventDescription && bashEventDescription.length > 10 ? bashEventDescription?.slice(0, 10) + '...' : bashEventDescription;
60
+ // Need to add characters if any of the args is undefined or else the params get thrown off
61
+ const params: string[] = [];
62
+ if (bashEventTitle) {
63
+ // params.push(`${URL_PARAMS_BASH_EVENT_TITLE}=${encodeURIComponent(bashEventTitle)}`);
64
+ }
65
+ if (desc) {
66
+ // params.push(`${URL_PARAMS_BASH_EVENT_DESC}=${encodeURIComponent(desc)}`);
67
+ }
68
+ if (coverPhoto) {
69
+ // params.push(`${URL_PARAMS_BASH_EVENT_COVER_PHOTO}=${encodeURIComponent(coverPhoto)}`);
70
+ }
71
+ return params.join('&');
72
+ }
73
+
74
+ export function isProduction(): boolean {
75
+ return process.env.NODE_ENV === 'production';
76
+ }