2022-04-14 21:25:24 +00:00
|
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
|
2022-03-17 19:36:11 +00:00
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|