chore: changes

This commit is contained in:
pit
2023-10-05 11:38:51 +03:00
committed by Mythie
parent 9151055936
commit af73aee113
5 changed files with 37 additions and 56 deletions

View File

@ -1,41 +0,0 @@
import { prisma } from '@documenso/prisma';
export const deleteUserAndItsData = async (name: string) => {
const user = await prisma.user.findFirst({
where: {
name: {
contains: name,
},
},
});
if (!user) {
throw new Error(`User with name ${name} not found`);
}
const document = await prisma.document.findMany({
where: {
userId: user.id,
},
select: {
documentData: {
select: {
data: true,
},
},
},
});
return prisma.$transaction([
prisma.user.delete({
where: {
id: user.id,
},
}),
prisma.documentData.deleteMany({
where: {
data: document[0]?.documentData.data,
},
}),
]);
};

View File

@ -0,0 +1,21 @@
import { prisma } from '@documenso/prisma';
export const deleteUser = async (name: string) => {
const user = await prisma.user.findFirst({
where: {
name: {
contains: name,
},
},
});
if (!user) {
throw new Error(`User with name ${name} not found`);
}
return await prisma.user.delete({
where: {
id: user.id,
},
});
};