calcom/pages/api/cancel.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

import prisma from '../../lib/prisma';
2021-06-07 06:59:13 +00:00
import {createEvent, deleteEvent} from "../../lib/calendarClient";
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,
2021-06-07 06:59:13 +00:00
user: true,
attendees: true,
references: true
}
});
2021-06-07 06:59:13 +00:00
await deleteEvent(bookingToDelete.user.credentials[0], uid);
await prisma.attendee.deleteMany({
where: {
bookingId: bookingToDelete.id
}
});
await prisma.bookingReference.deleteMany({
where: {
bookingId: bookingToDelete.id
}
});
//TODO Delete booking from calendar integrations
2021-06-06 23:10:56 +00:00
//TODO Perhaps send emails to user and client to tell about the cancellation
const deleteBooking = await prisma.booking.delete({
where: {
id: bookingToDelete.id,
},
});
res.status(200).json({message: 'Booking deleted successfully'});
}
}