N-FIN-75: update related payments before deleting category

This commit is contained in:
Markus Thielker 2024-12-23 19:44:06 +01:00
parent 155ab2f2e3
commit 4834750659
No known key found for this signature in database

View file

@ -38,15 +38,25 @@ export default async function categoryDelete(id: number): Promise<ActionResponse
};
}
// delete category
try {
await prisma.category.delete({
await prisma.$transaction(async (tx) => {
// update related payments
await tx.payment.updateMany({
where: {categoryId: category.id},
data: {categoryId: null},
});
// delete the category
await tx.category.delete({
where: {
id: category.id,
userId: user.sub,
},
},
);
});
});
} catch (e) {
return {
type: 'error',