2022-05-05 21:16:25 +00:00
|
|
|
import { recurringEvent } from "@calcom/prisma/zod-utils";
|
|
|
|
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2021-11-26 11:03:43 +00:00
|
|
|
import AttendeeAwaitingPaymentEmail from "@lib/emails/templates/attendee-awaiting-payment-email";
|
|
|
|
import AttendeeCancelledEmail from "@lib/emails/templates/attendee-cancelled-email";
|
|
|
|
import AttendeeDeclinedEmail from "@lib/emails/templates/attendee-declined-email";
|
2022-03-07 18:18:23 +00:00
|
|
|
import AttendeeRequestEmail from "@lib/emails/templates/attendee-request-email";
|
2022-04-14 21:25:24 +00:00
|
|
|
import AttendeeRequestRescheduledEmail from "@lib/emails/templates/attendee-request-reschedule-email";
|
2021-11-26 11:03:43 +00:00
|
|
|
import AttendeeRescheduledEmail from "@lib/emails/templates/attendee-rescheduled-email";
|
|
|
|
import AttendeeScheduledEmail from "@lib/emails/templates/attendee-scheduled-email";
|
|
|
|
import ForgotPasswordEmail, { PasswordReset } from "@lib/emails/templates/forgot-password-email";
|
|
|
|
import OrganizerCancelledEmail from "@lib/emails/templates/organizer-cancelled-email";
|
|
|
|
import OrganizerPaymentRefundFailedEmail from "@lib/emails/templates/organizer-payment-refund-failed-email";
|
|
|
|
import OrganizerRequestEmail from "@lib/emails/templates/organizer-request-email";
|
|
|
|
import OrganizerRequestReminderEmail from "@lib/emails/templates/organizer-request-reminder-email";
|
2022-04-14 21:25:24 +00:00
|
|
|
import OrganizerRequestRescheduleEmail from "@lib/emails/templates/organizer-request-reschedule-email";
|
2021-11-26 11:03:43 +00:00
|
|
|
import OrganizerRescheduledEmail from "@lib/emails/templates/organizer-rescheduled-email";
|
|
|
|
import OrganizerScheduledEmail from "@lib/emails/templates/organizer-scheduled-email";
|
|
|
|
import TeamInviteEmail, { TeamInvite } from "@lib/emails/templates/team-invite-email";
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendScheduledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new AttendeeScheduledEmail(calEvent, attendee, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new OrganizerScheduledEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendRescheduledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new AttendeeRescheduledEmail(calEvent, attendee, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new OrganizerRescheduledEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendOrganizerRequestEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
recurringEvent: RecurringEvent = {}
|
|
|
|
) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const organizerRequestEmail = new OrganizerRequestEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(organizerRequestEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerRequestEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendAttendeeRequestEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
attendee: Person,
|
|
|
|
recurringEvent: RecurringEvent = {}
|
|
|
|
) => {
|
2022-03-07 18:18:23 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const attendeeRequestEmail = new AttendeeRequestEmail(calEvent, attendee, recurringEvent);
|
2022-03-07 18:18:23 +00:00
|
|
|
resolve(attendeeRequestEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendRequestEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendDeclinedEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const declinedEmail = new AttendeeDeclinedEmail(calEvent, attendee, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(declinedEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendCancelledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new AttendeeCancelledEmail(calEvent, attendee, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeCancelledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const scheduledEmail = new OrganizerCancelledEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(scheduledEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerCancelledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendOrganizerRequestReminderEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
recurringEvent: RecurringEvent = {}
|
|
|
|
) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const organizerRequestReminderEmail = new OrganizerRequestReminderEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(organizerRequestReminderEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerRequestReminderEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendAwaitingPaymentEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
recurringEvent: RecurringEvent = {}
|
|
|
|
) => {
|
2022-02-10 17:42:06 +00:00
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
2021-11-26 11:03:43 +00:00
|
|
|
|
|
|
|
emailsToSend.push(
|
2022-02-10 17:42:06 +00:00
|
|
|
...calEvent.attendees.map((attendee) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const paymentEmail = new AttendeeAwaitingPaymentEmail(calEvent, attendee, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(paymentEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeAwaitingPaymentEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:16:25 +00:00
|
|
|
export const sendOrganizerPaymentRefundFailedEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
|
|
|
recurringEvent: RecurringEvent = {}
|
|
|
|
) => {
|
2021-11-26 11:03:43 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const paymentRefundFailedEmail = new OrganizerPaymentRefundFailedEmail(calEvent, recurringEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
resolve(paymentRefundFailedEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerPaymentRefundFailedEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sendPasswordResetEmail = async (passwordResetEvent: PasswordReset) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const passwordResetEmail = new ForgotPasswordEmail(passwordResetEvent);
|
|
|
|
resolve(passwordResetEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerPaymentRefundFailedEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sendTeamInviteEmail = async (teamInviteEvent: TeamInvite) => {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const teamInviteEmail = new TeamInviteEmail(teamInviteEvent);
|
|
|
|
resolve(teamInviteEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("TeamInviteEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
export const sendRequestRescheduleEmail = async (
|
|
|
|
calEvent: CalendarEvent,
|
2022-05-05 21:16:25 +00:00
|
|
|
metadata: { rescheduleLink: string },
|
|
|
|
recurringEvent: RecurringEvent = {}
|
2022-04-14 21:25:24 +00:00
|
|
|
) => {
|
|
|
|
const emailsToSend: Promise<unknown>[] = [];
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const requestRescheduleEmail = new AttendeeRequestRescheduledEmail(
|
|
|
|
calEvent,
|
|
|
|
metadata,
|
|
|
|
recurringEvent
|
|
|
|
);
|
2022-04-14 21:25:24 +00:00
|
|
|
resolve(requestRescheduleEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("AttendeeRequestRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
emailsToSend.push(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
try {
|
2022-05-05 21:16:25 +00:00
|
|
|
const requestRescheduleEmail = new OrganizerRequestRescheduleEmail(
|
|
|
|
calEvent,
|
|
|
|
metadata,
|
|
|
|
recurringEvent
|
|
|
|
);
|
2022-04-14 21:25:24 +00:00
|
|
|
resolve(requestRescheduleEmail.sendEmail());
|
|
|
|
} catch (e) {
|
|
|
|
reject(console.error("OrganizerRequestRescheduledEmail.sendEmail failed", e));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(emailsToSend);
|
|
|
|
};
|