From d05ae49e8d8cb41f6a3db531b58903a7ab9782b6 Mon Sep 17 00:00:00 2001 From: nicolas Date: Sun, 6 Jun 2021 03:51:24 +0200 Subject: [PATCH] Made UID unique, implemented cancel API, Prepared mail footer, --- lib/emails/confirm-booked.ts | 10 ++++- pages/api/cancel.ts | 40 +++++++++++++++++++ .../migration.sql | 8 ++++ prisma/schema.prisma | 2 +- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 pages/api/cancel.ts create mode 100644 prisma/migrations/20210606013704_made_booking_uid_unique/migration.sql diff --git a/lib/emails/confirm-booked.ts b/lib/emails/confirm-booked.ts index 32c4569515..c792e4f5e0 100644 --- a/lib/emails/confirm-booked.ts +++ b/lib/emails/confirm-booked.ts @@ -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(calEvent.startTime).tz(calEvent.attendees[0].timeZone); return ` @@ -58,7 +62,11 @@ const html = (calEvent: CalendarEvent) => { calEvent.location ? `Location: ${calEvent.location}

` : '' ) + `Additional notes:
- ${calEvent.description} + ${calEvent.description}
+
+ Need to change this event?
+ Cancel: {cancelLink}
+ Reschedule: {rescheduleLink} `; }; diff --git a/pages/api/cancel.ts b/pages/api/cancel.ts new file mode 100644 index 0000000000..c5fb534105 --- /dev/null +++ b/pages/api/cancel.ts @@ -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'}); + } +} \ No newline at end of file diff --git a/prisma/migrations/20210606013704_made_booking_uid_unique/migration.sql b/prisma/migrations/20210606013704_made_booking_uid_unique/migration.sql new file mode 100644 index 0000000000..e510da7c0e --- /dev/null +++ b/prisma/migrations/20210606013704_made_booking_uid_unique/migration.sql @@ -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"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index aa58d8a963..593308e4aa 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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[]