Implemented reschedule mail and fixed bug that rescheduling weren't saved
This commit is contained in:
parent
a11641d7b9
commit
869ba9b97c
6 changed files with 440 additions and 297 deletions
|
@ -2,6 +2,8 @@ import EventOwnerMail from "./emails/EventOwnerMail";
|
||||||
import EventAttendeeMail from "./emails/EventAttendeeMail";
|
import EventAttendeeMail from "./emails/EventAttendeeMail";
|
||||||
import {v5 as uuidv5} from 'uuid';
|
import {v5 as uuidv5} from 'uuid';
|
||||||
import short from 'short-uuid';
|
import short from 'short-uuid';
|
||||||
|
import EventOwnerRescheduledMail from "./emails/EventOwnerRescheduledMail";
|
||||||
|
import EventAttendeeRescheduledMail from "./emails/EventAttendeeRescheduledMail";
|
||||||
|
|
||||||
const translator = short();
|
const translator = short();
|
||||||
|
|
||||||
|
@ -291,7 +293,7 @@ const GoogleCalendar = (credential): CalendarApiAdapter => {
|
||||||
return resolve(event.data);
|
return resolve(event.data);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
deleteEvent: (uid: String) => new Promise( (resolve, reject) => {
|
deleteEvent: (uid: String) => new Promise((resolve, reject) => {
|
||||||
const calendar = google.calendar({version: 'v3', auth: myGoogleAuth});
|
const calendar = google.calendar({version: 'v3', auth: myGoogleAuth});
|
||||||
calendar.events.delete({
|
calendar.events.delete({
|
||||||
auth: myGoogleAuth,
|
auth: myGoogleAuth,
|
||||||
|
@ -338,7 +340,7 @@ const createEvent = async (credential, calEvent: CalendarEvent): Promise<any> =>
|
||||||
const attendeeMail = new EventAttendeeMail(calEvent, uid);
|
const attendeeMail = new EventAttendeeMail(calEvent, uid);
|
||||||
await ownerMail.sendEmail();
|
await ownerMail.sendEmail();
|
||||||
|
|
||||||
if(!creationResult || !creationResult.disableConfirmationEmail) {
|
if (!creationResult || !creationResult.disableConfirmationEmail) {
|
||||||
await attendeeMail.sendEmail();
|
await attendeeMail.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,12 +350,23 @@ const createEvent = async (credential, calEvent: CalendarEvent): Promise<any> =>
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateEvent = (credential, uid: String, calEvent: CalendarEvent): Promise<any> => {
|
const updateEvent = async (credential, uidToUpdate: String, calEvent: CalendarEvent): Promise<any> => {
|
||||||
if (credential) {
|
const newUid: string = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
||||||
return calendars([credential])[0].updateEvent(uid, calEvent);
|
|
||||||
|
const updateResult = credential ? await calendars([credential])[0].updateEvent(uidToUpdate, calEvent) : null;
|
||||||
|
|
||||||
|
const ownerMail = new EventOwnerRescheduledMail(calEvent, newUid);
|
||||||
|
const attendeeMail = new EventAttendeeRescheduledMail(calEvent, newUid);
|
||||||
|
await ownerMail.sendEmail();
|
||||||
|
|
||||||
|
if (!updateResult || !updateResult.disableConfirmationEmail) {
|
||||||
|
await attendeeMail.sendEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({});
|
return {
|
||||||
|
uid: newUid,
|
||||||
|
updatedEvent: updateResult
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteEvent = (credential, uid: String): Promise<any> => {
|
const deleteEvent = (credential, uid: String): Promise<any> => {
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default class EventAttendeeMail extends EventMail {
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private getInviteeStart(): Dayjs {
|
protected getInviteeStart(): Dayjs {
|
||||||
return <Dayjs>dayjs(this.calEvent.startTime).tz(this.calEvent.attendees[0].timeZone);
|
return <Dayjs>dayjs(this.calEvent.startTime).tz(this.calEvent.attendees[0].timeZone);
|
||||||
}
|
}
|
||||||
}
|
}
|
40
lib/emails/EventAttendeeRescheduledMail.ts
Normal file
40
lib/emails/EventAttendeeRescheduledMail.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import EventAttendeeMail from "./EventAttendeeMail";
|
||||||
|
|
||||||
|
export default class EventAttendeeRescheduledMail extends EventAttendeeMail {
|
||||||
|
/**
|
||||||
|
* Returns the email text as HTML representation.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected getHtmlRepresentation(): string {
|
||||||
|
return `
|
||||||
|
<div>
|
||||||
|
Hi ${this.calEvent.attendees[0].name},<br />
|
||||||
|
<br />
|
||||||
|
Your ${this.calEvent.type} with ${this.calEvent.organizer.name} has been rescheduled to ${this.getInviteeStart().format('h:mma')}
|
||||||
|
(${this.calEvent.attendees[0].timeZone}) on ${this.getInviteeStart().format('dddd, LL')}.<br />
|
||||||
|
` + this.getAdditionalFooter() + `
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the payload object for the nodemailer.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected getNodeMailerPayload(): Object {
|
||||||
|
return {
|
||||||
|
to: `${this.calEvent.attendees[0].name} <${this.calEvent.attendees[0].email}>`,
|
||||||
|
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
|
||||||
|
replyTo: this.calEvent.organizer.email,
|
||||||
|
subject: `Rescheduled: ${this.calEvent.type} with ${this.calEvent.organizer.name} on ${this.getInviteeStart().format('dddd, LL')}`,
|
||||||
|
html: this.getHtmlRepresentation(),
|
||||||
|
text: this.getPlainTextRepresentation(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected printNodeMailerError(error: string): void {
|
||||||
|
console.error("SEND_RESCHEDULE_CONFIRMATION_ERROR", this.calEvent.attendees[0].email, error);
|
||||||
|
}
|
||||||
|
}
|
64
lib/emails/EventOwnerRescheduledMail.ts
Normal file
64
lib/emails/EventOwnerRescheduledMail.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import dayjs, {Dayjs} from "dayjs";
|
||||||
|
import EventOwnerMail from "./EventOwnerMail";
|
||||||
|
|
||||||
|
export default class EventOwnerRescheduledMail extends EventOwnerMail {
|
||||||
|
/**
|
||||||
|
* Returns the email text as HTML representation.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected getHtmlRepresentation(): string {
|
||||||
|
return `
|
||||||
|
<div>
|
||||||
|
Hi ${this.calEvent.organizer.name},<br />
|
||||||
|
<br />
|
||||||
|
Your event has been rescheduled.<br />
|
||||||
|
<br />
|
||||||
|
<strong>Event Type:</strong><br />
|
||||||
|
${this.calEvent.type}<br />
|
||||||
|
<br />
|
||||||
|
<strong>Invitee Email:</strong><br />
|
||||||
|
<a href="mailto:${this.calEvent.attendees[0].email}">${this.calEvent.attendees[0].email}</a><br />
|
||||||
|
<br />` + this.getAdditionalBody() +
|
||||||
|
(
|
||||||
|
this.calEvent.location ? `
|
||||||
|
<strong>Location:</strong><br />
|
||||||
|
${this.calEvent.location}<br />
|
||||||
|
<br />
|
||||||
|
` : ''
|
||||||
|
) +
|
||||||
|
`<strong>Invitee Time Zone:</strong><br />
|
||||||
|
${this.calEvent.attendees[0].timeZone}<br />
|
||||||
|
<br />
|
||||||
|
<strong>Additional notes:</strong><br />
|
||||||
|
${this.calEvent.description}
|
||||||
|
` + this.getAdditionalFooter() + `
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the payload object for the nodemailer.
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected getNodeMailerPayload(): Object {
|
||||||
|
const organizerStart: Dayjs = <Dayjs>dayjs(this.calEvent.startTime).tz(this.calEvent.organizer.timeZone);
|
||||||
|
|
||||||
|
return {
|
||||||
|
icalEvent: {
|
||||||
|
filename: 'event.ics',
|
||||||
|
content: this.getiCalEventAsString(),
|
||||||
|
},
|
||||||
|
from: `Calendso <${this.getMailerOptions().from}>`,
|
||||||
|
to: this.calEvent.organizer.email,
|
||||||
|
subject: `Rescheduled event: ${this.calEvent.attendees[0].name} - ${organizerStart.format('LT dddd, LL')} - ${this.calEvent.type}`,
|
||||||
|
html: this.getHtmlRepresentation(),
|
||||||
|
text: this.getPlainTextRepresentation(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected printNodeMailerError(error: string): void {
|
||||||
|
console.error("SEND_RESCHEDULE_EVENT_NOTIFICATION_ERROR", this.calEvent.organizer.email, error);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ import VideoEventOwnerMail from "./emails/VideoEventOwnerMail";
|
||||||
import VideoEventAttendeeMail from "./emails/VideoEventAttendeeMail";
|
import VideoEventAttendeeMail from "./emails/VideoEventAttendeeMail";
|
||||||
import {v5 as uuidv5} from 'uuid';
|
import {v5 as uuidv5} from 'uuid';
|
||||||
import short from 'short-uuid';
|
import short from 'short-uuid';
|
||||||
|
import EventAttendeeRescheduledMail from "./emails/EventAttendeeRescheduledMail";
|
||||||
|
import EventOwnerRescheduledMail from "./emails/EventOwnerRescheduledMail";
|
||||||
|
|
||||||
const translator = short();
|
const translator = short();
|
||||||
|
|
||||||
|
@ -203,12 +205,27 @@ const createMeeting = async (credential, calEvent: CalendarEvent): Promise<any>
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateMeeting = (credential, uid: String, event: CalendarEvent): Promise<any> => {
|
const updateMeeting = async (credential, uidToUpdate: String, calEvent: CalendarEvent): Promise<any> => {
|
||||||
if (credential) {
|
const newUid: string = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
||||||
return videoIntegrations([credential])[0].updateMeeting(uid, event);
|
|
||||||
|
if (!credential) {
|
||||||
|
throw new Error("Credentials must be set! Video platforms are optional, so this method shouldn't even be called when no video credentials are set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({});
|
const updateResult = credential ? await videoIntegrations([credential])[0].updateMeeting(uidToUpdate, calEvent) : null;
|
||||||
|
|
||||||
|
const ownerMail = new EventOwnerRescheduledMail(calEvent, newUid);
|
||||||
|
const attendeeMail = new EventAttendeeRescheduledMail(calEvent, newUid);
|
||||||
|
await ownerMail.sendEmail();
|
||||||
|
|
||||||
|
if (!updateResult || !updateResult.disableConfirmationEmail) {
|
||||||
|
await attendeeMail.sendEmail();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
uid: newUid,
|
||||||
|
updatedEvent: updateResult
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteMeeting = (credential, uid: String): Promise<any> => {
|
const deleteMeeting = (credential, uid: String): Promise<any> => {
|
||||||
|
|
|
@ -78,12 +78,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
// Use all integrations
|
// Use all integrations
|
||||||
results = results.concat(await async.mapLimit(calendarCredentials, 5, async (credential) => {
|
results = results.concat(await async.mapLimit(calendarCredentials, 5, async (credential) => {
|
||||||
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
|
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
|
||||||
return await updateEvent(credential, bookingRefUid, evt)
|
const response = await updateEvent(credential, bookingRefUid, evt);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: credential.type,
|
||||||
|
response
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
results = results.concat(await async.mapLimit(videoCredentials, 5, async (credential) => {
|
results = results.concat(await async.mapLimit(videoCredentials, 5, async (credential) => {
|
||||||
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
|
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
|
||||||
return await updateMeeting(credential, bookingRefUid, evt)
|
const response = await updateMeeting(credential, bookingRefUid, evt);
|
||||||
|
return {
|
||||||
|
type: credential.type,
|
||||||
|
response
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Clone elements
|
// Clone elements
|
||||||
|
|
Loading…
Reference in a new issue