2023-10-05 11:38:51 +03:00
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
|
|
2023-10-14 00:20:11 +11:00
|
|
|
export type DeleteUserOptions = {
|
|
|
|
|
email: string;
|
2023-10-17 12:40:36 +11:00
|
|
|
};
|
2023-10-14 00:20:11 +11:00
|
|
|
|
|
|
|
|
export const deleteUser = async ({ email }: DeleteUserOptions) => {
|
2023-10-05 11:38:51 +03:00
|
|
|
const user = await prisma.user.findFirst({
|
|
|
|
|
where: {
|
2023-10-12 12:19:23 +03:00
|
|
|
email: {
|
|
|
|
|
contains: email,
|
2023-10-05 11:38:51 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
2023-10-12 12:19:23 +03:00
|
|
|
throw new Error(`User with email ${email} not found`);
|
2023-10-05 11:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await prisma.user.delete({
|
|
|
|
|
where: {
|
|
|
|
|
id: user.id,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|