feat: add translations for emails and type error fixes overall (#994)
* feat: add translations for forgot password email and misc * fix: type fixes * feat: translate invitation email * fix: e2e tests * fix: lint * feat: type fixes and i18n for emails * Merge main * fix: jest import on server path * Merge * fix: playwright tests * fix: lint Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
1 parent
356d470e16
commit
8d6fec79d3
35 files changed
+680
-461
No files matched your search
+93
-85
@@ -3,7 +3,7 @@ import async from "async";
|
||||
import merge from "lodash/merge";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
import { CalendarEvent, createEvent, updateEvent } from "@lib/calendarClient";
|
||||
import { CalendarEvent, AdditionInformation, createEvent, updateEvent } from "@lib/calendarClient";
|
||||
import { dailyCreateMeeting, dailyUpdateMeeting } from "@lib/dailyVideoClient";
|
||||
import EventAttendeeMail from "@lib/emails/EventAttendeeMail";
|
||||
import EventAttendeeRescheduledMail from "@lib/emails/EventAttendeeRescheduledMail";
|
||||
@@ -15,8 +15,8 @@ export interface EventResult {
|
||||
type: string;
|
||||
success: boolean;
|
||||
uid: string;
|
||||
createdEvent?: unknown;
|
||||
updatedEvent?: unknown;
|
||||
createdEvent?: AdditionInformation & { name: string; id: string; disableConfirmationEmail?: boolean };
|
||||
updatedEvent?: AdditionInformation & { name: string; id: string; disableConfirmationEmail?: boolean };
|
||||
originalEvent: CalendarEvent;
|
||||
videoCallData?: VideoCallData;
|
||||
}
|
||||
@@ -35,9 +35,9 @@ export interface PartialReference {
|
||||
id?: number;
|
||||
type: string;
|
||||
uid: string;
|
||||
meetingId?: string;
|
||||
meetingPassword?: string;
|
||||
meetingUrl?: string;
|
||||
meetingId?: string | null;
|
||||
meetingPassword?: string | null;
|
||||
meetingUrl?: string | null;
|
||||
}
|
||||
|
||||
interface GetLocationRequestFromIntegrationRequest {
|
||||
@@ -78,55 +78,46 @@ export default class EventManager {
|
||||
* Takes a CalendarEvent and creates all necessary integration entries for it.
|
||||
* When a video integration is chosen as the event's location, a video integration
|
||||
* event will be scheduled for it as well.
|
||||
* An optional uid can be set to override the auto-generated uid.
|
||||
*
|
||||
* @param event
|
||||
* @param maybeUid
|
||||
*/
|
||||
public async create(event: CalendarEvent, maybeUid?: string): Promise<CreateUpdateResult> {
|
||||
event = EventManager.processLocation(event);
|
||||
const isDedicated = EventManager.isDedicatedIntegration(event.location);
|
||||
public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
|
||||
let evt = EventManager.processLocation(event);
|
||||
const isDedicated = evt.location ? EventManager.isDedicatedIntegration(evt.location) : null;
|
||||
|
||||
let results: Array<EventResult> = [];
|
||||
let optionalVideoCallData: VideoCallData | undefined = undefined;
|
||||
|
||||
// If and only if event type is a dedicated meeting, create a dedicated video meeting.
|
||||
if (isDedicated) {
|
||||
const result = await this.createVideoEvent(event, maybeUid);
|
||||
const result = await this.createVideoEvent(evt);
|
||||
if (result.videoCallData) {
|
||||
optionalVideoCallData = result.videoCallData;
|
||||
evt = { ...evt, videoCallData: result.videoCallData };
|
||||
}
|
||||
results.push(result);
|
||||
} else {
|
||||
await EventManager.sendAttendeeMail("new", results, event, maybeUid);
|
||||
await EventManager.sendAttendeeMail("new", results, evt);
|
||||
}
|
||||
|
||||
// Now create all calendar events. If this is a dedicated integration event,
|
||||
// don't send a mail right here, because it has already been sent.
|
||||
results = results.concat(
|
||||
await this.createAllCalendarEvents(event, isDedicated, maybeUid, optionalVideoCallData)
|
||||
);
|
||||
results = results.concat(await this.createAllCalendarEvents(evt, isDedicated));
|
||||
|
||||
const referencesToCreate: Array<PartialReference> = results.map((result: EventResult) => {
|
||||
const isDailyResult = result.type === "daily";
|
||||
if (isDailyResult) {
|
||||
return {
|
||||
type: result.type,
|
||||
uid: result.createdEvent.name.toString(),
|
||||
meetingId: result.videoCallData?.id.toString(),
|
||||
meetingPassword: result.videoCallData?.password,
|
||||
meetingUrl: result.videoCallData?.url,
|
||||
};
|
||||
let uid = "";
|
||||
if (isDailyResult && result.createdEvent) {
|
||||
uid = result.createdEvent.name.toString();
|
||||
}
|
||||
if (!isDailyResult) {
|
||||
return {
|
||||
type: result.type,
|
||||
uid: result.createdEvent.id.toString(),
|
||||
meetingId: result.videoCallData?.id.toString(),
|
||||
meetingPassword: result.videoCallData?.password,
|
||||
meetingUrl: result.videoCallData?.url,
|
||||
};
|
||||
if (!isDailyResult && result.createdEvent) {
|
||||
uid = result.createdEvent.id.toString();
|
||||
}
|
||||
return {
|
||||
type: result.type,
|
||||
uid,
|
||||
meetingId: result.videoCallData?.id.toString(),
|
||||
meetingPassword: result.videoCallData?.password,
|
||||
meetingUrl: result.videoCallData?.url,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -140,15 +131,18 @@ export default class EventManager {
|
||||
* given uid using the data delivered in the given CalendarEvent.
|
||||
*
|
||||
* @param event
|
||||
* @param rescheduleUid
|
||||
*/
|
||||
public async update(event: CalendarEvent, rescheduleUid: string): Promise<CreateUpdateResult> {
|
||||
event = EventManager.processLocation(event);
|
||||
public async update(event: CalendarEvent): Promise<CreateUpdateResult> {
|
||||
let evt = EventManager.processLocation(event);
|
||||
|
||||
if (!evt.uid) {
|
||||
throw new Error("missing uid");
|
||||
}
|
||||
|
||||
// Get details of existing booking.
|
||||
const booking = await prisma.booking.findFirst({
|
||||
where: {
|
||||
uid: rescheduleUid,
|
||||
uid: evt.uid,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -165,28 +159,30 @@ export default class EventManager {
|
||||
},
|
||||
});
|
||||
|
||||
const isDedicated =
|
||||
EventManager.isDedicatedIntegration(event.location) || event.location === dailyLocation;
|
||||
if (!booking) {
|
||||
throw new Error("booking not found");
|
||||
}
|
||||
|
||||
const isDedicated = evt.location
|
||||
? EventManager.isDedicatedIntegration(evt.location) || evt.location === dailyLocation
|
||||
: null;
|
||||
|
||||
let results: Array<EventResult> = [];
|
||||
let optionalVideoCallData: VideoCallData | undefined = undefined;
|
||||
|
||||
// If and only if event type is a dedicated meeting, update the dedicated video meeting.
|
||||
if (isDedicated) {
|
||||
const result = await this.updateVideoEvent(event, booking);
|
||||
const result = await this.updateVideoEvent(evt, booking);
|
||||
if (result.videoCallData) {
|
||||
optionalVideoCallData = result.videoCallData;
|
||||
evt = { ...evt, videoCallData: result.videoCallData };
|
||||
}
|
||||
results.push(result);
|
||||
} else {
|
||||
await EventManager.sendAttendeeMail("reschedule", results, event, rescheduleUid);
|
||||
await EventManager.sendAttendeeMail("reschedule", results, evt);
|
||||
}
|
||||
|
||||
// Now update all calendar events. If this is a dedicated integration event,
|
||||
// don't send a mail right here, because it has already been sent.
|
||||
results = results.concat(
|
||||
await this.updateAllCalendarEvents(event, booking, isDedicated, optionalVideoCallData)
|
||||
);
|
||||
results = results.concat(await this.updateAllCalendarEvents(evt, booking, isDedicated));
|
||||
|
||||
// Now we can delete the old booking and its references.
|
||||
const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
|
||||
@@ -199,11 +195,16 @@ export default class EventManager {
|
||||
bookingId: booking.id,
|
||||
},
|
||||
});
|
||||
const bookingDeletes = prisma.booking.delete({
|
||||
where: {
|
||||
uid: rescheduleUid,
|
||||
},
|
||||
});
|
||||
|
||||
let bookingDeletes = null;
|
||||
|
||||
if (evt.uid) {
|
||||
bookingDeletes = prisma.booking.delete({
|
||||
where: {
|
||||
uid: evt.uid,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Wait for all deletions to be applied.
|
||||
await Promise.all([bookingReferenceDeletes, attendeeDeletes, bookingDeletes]);
|
||||
@@ -224,19 +225,12 @@ export default class EventManager {
|
||||
*
|
||||
* @param event
|
||||
* @param noMail
|
||||
* @param maybeUid
|
||||
* @param optionalVideoCallData
|
||||
* @private
|
||||
*/
|
||||
|
||||
private createAllCalendarEvents(
|
||||
event: CalendarEvent,
|
||||
noMail: boolean,
|
||||
maybeUid?: string,
|
||||
optionalVideoCallData?: VideoCallData
|
||||
): Promise<Array<EventResult>> {
|
||||
private createAllCalendarEvents(event: CalendarEvent, noMail: boolean | null): Promise<Array<EventResult>> {
|
||||
return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => {
|
||||
return createEvent(credential, event, noMail, maybeUid, optionalVideoCallData);
|
||||
return createEvent(credential, event, noMail);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -248,6 +242,10 @@ export default class EventManager {
|
||||
*/
|
||||
|
||||
private getVideoCredential(event: CalendarEvent): Credential | undefined {
|
||||
if (!event.location) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const integrationName = event.location.replace("integrations:", "");
|
||||
|
||||
return this.videoCredentials.find((credential: Credential) => credential.type.includes(integrationName));
|
||||
@@ -259,18 +257,17 @@ export default class EventManager {
|
||||
* When optional uid is set, it will be used instead of the auto generated uid.
|
||||
*
|
||||
* @param event
|
||||
* @param maybeUid
|
||||
* @private
|
||||
*/
|
||||
private createVideoEvent(event: CalendarEvent, maybeUid?: string): Promise<EventResult> {
|
||||
private createVideoEvent(event: CalendarEvent): Promise<EventResult> {
|
||||
const credential = this.getVideoCredential(event);
|
||||
|
||||
const isDaily = event.location === dailyLocation;
|
||||
|
||||
if (credential && !isDaily) {
|
||||
return createMeeting(credential, event, maybeUid);
|
||||
} else if (isDaily) {
|
||||
return dailyCreateMeeting(credential, event, maybeUid);
|
||||
return createMeeting(credential, event);
|
||||
} else if (credential && isDaily) {
|
||||
return dailyCreateMeeting(credential, event);
|
||||
} else {
|
||||
return Promise.reject("No suitable credentials given for the requested integration name.");
|
||||
}
|
||||
@@ -289,13 +286,15 @@ export default class EventManager {
|
||||
*/
|
||||
private updateAllCalendarEvents(
|
||||
event: CalendarEvent,
|
||||
booking: PartialBooking,
|
||||
noMail: boolean,
|
||||
optionalVideoCallData?: VideoCallData
|
||||
booking: PartialBooking | null,
|
||||
noMail: boolean | null
|
||||
): Promise<Array<EventResult>> {
|
||||
return async.mapLimit(this.calendarCredentials, 5, async (credential) => {
|
||||
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0]?.uid;
|
||||
return updateEvent(credential, bookingRefUid, event, noMail, optionalVideoCallData);
|
||||
const bookingRefUid = booking
|
||||
? booking.references.filter((ref) => ref.type === credential.type)[0]?.uid
|
||||
: null;
|
||||
const evt = { ...event, uid: bookingRefUid };
|
||||
return updateEvent(credential, evt, noMail);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -311,9 +310,9 @@ export default class EventManager {
|
||||
const isDaily = event.location === dailyLocation;
|
||||
|
||||
if (credential && !isDaily) {
|
||||
const bookingRef = booking.references.filter((ref) => ref.type === credential.type)[0];
|
||||
|
||||
return updateMeeting(credential, bookingRef.uid, event).then((returnVal: EventResult) => {
|
||||
const bookingRef = booking ? booking.references.filter((ref) => ref.type === credential.type)[0] : null;
|
||||
const evt = { ...event, uid: bookingRef?.uid };
|
||||
return updateMeeting(credential, evt).then((returnVal: EventResult) => {
|
||||
// Some video integrations, such as Zoom, don't return any data about the booking when updating it.
|
||||
if (returnVal.videoCallData == undefined) {
|
||||
returnVal.videoCallData = EventManager.bookingReferenceToVideoCallData(bookingRef);
|
||||
@@ -321,9 +320,12 @@ export default class EventManager {
|
||||
return returnVal;
|
||||
});
|
||||
} else {
|
||||
if (isDaily) {
|
||||
const bookingRefUid = booking.references.filter((ref) => ref.type === "daily")[0].uid;
|
||||
return dailyUpdateMeeting(credential, bookingRefUid, event);
|
||||
if (credential && isDaily) {
|
||||
const bookingRefUid = booking
|
||||
? booking.references.filter((ref) => ref.type === "daily")[0].uid
|
||||
: null;
|
||||
const evt = { ...event, uid: bookingRefUid };
|
||||
return dailyUpdateMeeting(credential, evt);
|
||||
}
|
||||
return Promise.reject("No suitable credentials given for the requested integration name.");
|
||||
}
|
||||
@@ -405,9 +407,15 @@ export default class EventManager {
|
||||
* @param reference
|
||||
* @private
|
||||
*/
|
||||
private static bookingReferenceToVideoCallData(reference: PartialReference): VideoCallData | undefined {
|
||||
private static bookingReferenceToVideoCallData(
|
||||
reference: PartialReference | null
|
||||
): VideoCallData | undefined {
|
||||
let isComplete = true;
|
||||
|
||||
if (!reference) {
|
||||
throw new Error("missing reference");
|
||||
}
|
||||
|
||||
switch (reference.type) {
|
||||
case "zoom_video":
|
||||
// Zoom meetings in our system should always have an ID, a password and a join URL. In the
|
||||
@@ -441,33 +449,33 @@ export default class EventManager {
|
||||
* @param type
|
||||
* @param results
|
||||
* @param event
|
||||
* @param maybeUid
|
||||
* @private
|
||||
*/
|
||||
private static async sendAttendeeMail(
|
||||
type: "new" | "reschedule",
|
||||
results: Array<EventResult>,
|
||||
event: CalendarEvent,
|
||||
maybeUid?: string
|
||||
event: CalendarEvent
|
||||
) {
|
||||
if (
|
||||
!results.length ||
|
||||
!results.some((eRes) => (eRes.createdEvent || eRes.updatedEvent).disableConfirmationEmail)
|
||||
!results.some((eRes) => (eRes.createdEvent || eRes.updatedEvent)?.disableConfirmationEmail)
|
||||
) {
|
||||
const metadata: { hangoutLink?: string; conferenceData?: unknown; entryPoints?: unknown } = {};
|
||||
const metadata: AdditionInformation = {};
|
||||
if (results.length) {
|
||||
// TODO: Handle created event metadata more elegantly
|
||||
metadata.hangoutLink = results[0].createdEvent?.hangoutLink;
|
||||
metadata.conferenceData = results[0].createdEvent?.conferenceData;
|
||||
metadata.entryPoints = results[0].createdEvent?.entryPoints;
|
||||
}
|
||||
const emailEvent = { ...event, additionInformation: metadata };
|
||||
|
||||
let attendeeMail;
|
||||
switch (type) {
|
||||
case "reschedule":
|
||||
attendeeMail = new EventAttendeeRescheduledMail(event, maybeUid, metadata);
|
||||
attendeeMail = new EventAttendeeRescheduledMail(emailEvent);
|
||||
break;
|
||||
case "new":
|
||||
attendeeMail = new EventAttendeeMail(event, maybeUid, metadata);
|
||||
attendeeMail = new EventAttendeeMail(emailEvent);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user