Skip to content

Commit

Permalink
fix issue with onCascade deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
CarinaWolli committed Aug 3, 2022
1 parent 029c517 commit 8d4cc75
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/trpc/server/routers/viewer/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,18 @@ export const workflowsRouter = createProtectedRouter()
async resolve({ ctx, input }) {
const { id } = input;

const deleted = await ctx.prisma.workflow.deleteMany({
const workflowToDelete = await ctx.prisma.workflow.findFirst({
where: {
AND: [
{ id },
{
userId: ctx.user.id,
},
{
id,
userId: ctx.user.id
},
],
},
});
]
}
})

if (deleted.count === 1) {
//delete all scheduled reminders of this workflow
if(workflowToDelete) {
const scheduledReminders = await ctx.prisma.workflowReminder.findMany({
where: {
workflowStep: {
Expand All @@ -173,6 +170,18 @@ export const workflowsRouter = createProtectedRouter()
}
});

await ctx.prisma.workflow.deleteMany({
where: {
AND: [
{
userId: ctx.user.id,
},
{
id,
},
],
},
});
}

return {
Expand Down

0 comments on commit 8d4cc75

Please sign in to comment.