Made UID unique, implemented cancel API, Prepared mail footer,

pull/253/head
nicolas 2021-06-06 03:51:24 +02:00
parent c29c0395ef
commit d05ae49e8d
4 changed files with 58 additions and 2 deletions

View File

@ -46,6 +46,10 @@ const sendEmail = (calEvent: CalendarEvent, {
)
});
//TODO: Get links
const cancelLink = "TODO";
const rescheduleLink = "TODO";
const html = (calEvent: CalendarEvent) => {
const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);
return `
@ -58,7 +62,11 @@ const html = (calEvent: CalendarEvent) => {
calEvent.location ? `<strong>Location:</strong> ${calEvent.location}<br /><br />` : ''
) +
`Additional notes:<br />
${calEvent.description}
${calEvent.description}<br />
<br />
Need to change this event?<br />
Cancel: {cancelLink}<br />
Reschedule: {rescheduleLink}
</div>
`;
};

40
pages/api/cancel.ts Normal file
View File

@ -0,0 +1,40 @@
import prisma from '../../lib/prisma';
export default async function handler(req, res) {
if (req.method == "POST") {
const uid = req.body.uid;
const bookingToDelete = await prisma.booking.findFirst({
where: {
uid: uid,
},
select: {
id: true,
attendees: true,
references: true
}
});
await prisma.attendee.deleteMany({
where: {
bookingId: bookingToDelete.id
}
});
await prisma.bookingReference.deleteMany({
where: {
bookingId: bookingToDelete.id
}
});
//TODO Delete booking from calendar integrations
const deleteBooking = await prisma.booking.delete({
where: {
id: bookingToDelete.id,
},
});
res.status(200).json({message: 'Booking deleted successfully'});
}
}

View File

@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[uid]` on the table `Booking` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "Booking.uid_unique" ON "Booking"("uid");

View File

@ -69,7 +69,7 @@ model Attendee {
model Booking {
id Int @default(autoincrement()) @id
uid String
uid String @unique
user User? @relation(fields: [userId], references: [id])
userId Int?
references BookingReference[]