2023-02-16 22:39:57 +00:00
|
|
|
import type { Prisma } from "@prisma/client";
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-17 19:36:11 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* DO NOT USE, since test run in parallel this will cause flaky tests. The reason
|
|
|
|
* being that a set of test may end earlier than other trigger a delete of all bookings
|
|
|
|
* than other tests may depend on them. The proper ettiquete should be that EACH test
|
|
|
|
* should cleanup ONLY the booking that we're created in that specific test to se DB
|
|
|
|
* remains "pristine" after each test
|
|
|
|
*/
|
2022-04-14 21:25:24 +00:00
|
|
|
export const deleteAllBookingsByEmail = async (
|
|
|
|
email: string,
|
|
|
|
whereConditional: Prisma.BookingWhereInput = {}
|
|
|
|
) =>
|
2022-03-17 19:36:11 +00:00
|
|
|
prisma.booking.deleteMany({
|
|
|
|
where: {
|
|
|
|
user: {
|
|
|
|
email,
|
|
|
|
},
|
2022-04-14 21:25:24 +00:00
|
|
|
...whereConditional,
|
2022-03-17 19:36:11 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const deleteEventTypeByTitle = async (title: string) => {
|
|
|
|
const event = (await prisma.eventType.findFirst({
|
|
|
|
select: { id: true },
|
|
|
|
where: { title: title },
|
|
|
|
}))!;
|
|
|
|
await prisma.eventType.delete({ where: { id: event.id } });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteAllWebhooksByEmail = async (email: string) => {
|
|
|
|
await prisma.webhook.deleteMany({
|
|
|
|
where: {
|
|
|
|
user: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteAllPaymentsByEmail = async (email: string) => {
|
|
|
|
await prisma.payment.deleteMany({
|
|
|
|
where: {
|
|
|
|
booking: {
|
|
|
|
user: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
export const deleteAllPaymentCredentialsByEmail = async (email: string) => {
|
|
|
|
await prisma.user.update({
|
|
|
|
where: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
credentials: {
|
|
|
|
deleteMany: {
|
|
|
|
type: {
|
|
|
|
endsWith: "_payment",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|