@bash-app/bash-common 29.43.0 → 29.44.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/package.json +1 -1
- package/src/extendedSchemas.ts +3 -0
- package/src/utils/dateTimeUtils.ts +52 -17
package/package.json
CHANGED
package/src/extendedSchemas.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
ServicePackage,
|
|
39
39
|
ServiceListingSubscription,
|
|
40
40
|
SocialMediaProfile,
|
|
41
|
+
SocialMediaPlatform,
|
|
41
42
|
} from "@prisma/client";
|
|
42
43
|
import { SERVICE_LINK_DATA_TO_INCLUDE, UnionFromArray } from "./definitions";
|
|
43
44
|
|
|
@@ -49,6 +50,7 @@ export const FRONT_END_USER_DATA_TO_SELECT = {
|
|
|
49
50
|
image: true,
|
|
50
51
|
uploadedImage: true,
|
|
51
52
|
isSuperUser: true,
|
|
53
|
+
socialMediaProfiles: true,
|
|
52
54
|
} satisfies Prisma.UserSelect;
|
|
53
55
|
|
|
54
56
|
export const PRIVATE_USER_ACCOUNT_TO_SELECT = {
|
|
@@ -525,6 +527,7 @@ export interface UserExt extends User {
|
|
|
525
527
|
associatedBashes?: AssociatedBash[] | null;
|
|
526
528
|
associatedServices?: AssociatedService[] | null;
|
|
527
529
|
socialMediaProfiles?: SocialMediaProfile[] | null;
|
|
530
|
+
socialMediaPlatforms?: SocialMediaPlatform[] | null;
|
|
528
531
|
reviews?: ReviewExt[] | null;
|
|
529
532
|
contacts?: Contact[] | null;
|
|
530
533
|
ticketsIOwn?: TicketExt[] | null;
|
|
@@ -40,25 +40,30 @@ export function ensureIsDateTime(possiblyADate: DateTimeArgType): Date | undefin
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function normalizeDate(validDate: Date | string | undefined | null): Date | undefined {
|
|
43
|
-
if (validDate)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
if (!validDate) return undefined;
|
|
44
|
+
|
|
45
|
+
// Convert to Date object if it's a string
|
|
46
|
+
const date = typeof validDate === "string" ? new Date(validDate) : validDate;
|
|
47
|
+
|
|
48
|
+
// Check if the date is valid
|
|
49
|
+
if (isNaN(date.getTime())) {
|
|
50
|
+
console.error("Invalid date provided:", validDate);
|
|
51
|
+
return undefined;
|
|
49
52
|
}
|
|
53
|
+
|
|
54
|
+
// Use dayjs to normalize the date and convert to UTC
|
|
55
|
+
const normalizedDate = dayjs(date).utc().startOf("minute").toDate();
|
|
56
|
+
|
|
57
|
+
return normalizedDate;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
export function normalizeDates(dates: Date[]): Date[] {
|
|
60
|
+
export function normalizeDates(dates: (Date | string | undefined | null)[]): Date[] {
|
|
53
61
|
return dates
|
|
54
|
-
.map((date)
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
.filter((dateTime: Date | undefined): boolean => {
|
|
58
|
-
return !!dateTime
|
|
59
|
-
}) as Date[];
|
|
62
|
+
.map((date) => normalizeDate(date)) // Normalize each date
|
|
63
|
+
.filter((date): date is Date => !!date); // Filter out invalid dates
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
|
|
62
67
|
export function formatDateTimeToISODateTimeString(date: DateTimeArgType): string | undefined {
|
|
63
68
|
if (!date) {
|
|
64
69
|
return undefined;
|
|
@@ -136,13 +141,43 @@ export function compareDateTime(date1: DateTimeArgType,
|
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
|
|
139
|
-
export function setDateButPreserveTime(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
export function setDateButPreserveTime(
|
|
145
|
+
dateArg: DateType,
|
|
146
|
+
dateWithTheTimeYouWantToKeep: DateType | undefined
|
|
147
|
+
): Date {
|
|
148
|
+
if (!dateArg || !dateWithTheTimeYouWantToKeep) {
|
|
149
|
+
console.error("Invalid arguments:", { dateArg, dateWithTheTimeYouWantToKeep });
|
|
150
|
+
throw new Error("Both dateArg and dateWithTheTimeYouWantToKeep are required.");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Get local timezone
|
|
154
|
+
const localTimeZone = dayjs.tz.guess();
|
|
155
|
+
|
|
156
|
+
// Format date and time parts
|
|
157
|
+
const datePart = dayjs(dateArg).tz(localTimeZone).format("YYYY-MM-DD"); // Local date
|
|
158
|
+
const timePart = dayjs(dateWithTheTimeYouWantToKeep).tz(localTimeZone).format("HH:mm"); // Local time
|
|
159
|
+
|
|
160
|
+
// Combine into an ISO string
|
|
161
|
+
const combinedDateTimeString = `${datePart}T${timePart}`;
|
|
162
|
+
console.log("Combining date and time:", {
|
|
163
|
+
datePart,
|
|
164
|
+
timePart,
|
|
165
|
+
combinedDateTimeString,
|
|
166
|
+
localTimeZone,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Convert to UTC
|
|
170
|
+
const combinedDateTime = dayjs.tz(combinedDateTimeString, localTimeZone).toDate();
|
|
171
|
+
if (isNaN(combinedDateTime.getTime())) {
|
|
172
|
+
console.error("Invalid combined datetime:", combinedDateTimeString);
|
|
173
|
+
throw new Error("Invalid date or time format.");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log("Final combined DateTime (UTC):", combinedDateTime);
|
|
143
177
|
return combinedDateTime;
|
|
144
178
|
}
|
|
145
179
|
|
|
180
|
+
|
|
146
181
|
export function setTimeOnDate(date: DateType | Date | undefined, parsedTime: ITime): Date {
|
|
147
182
|
const dateTime = new Date(date ?? Date.now());
|
|
148
183
|
const parsedTimeDate = new Date();
|