Skip to content

Commit

Permalink
🐛 Fix can’t delete user with deleted polls (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored Oct 20, 2024
1 parent 501cdd2 commit 82eb076
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 2 additions & 0 deletions apps/web/src/trpc/routers/polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const polls = router({
return await prisma.poll.findMany({
where: {
userId: ctx.user.id,
deleted: false,
status: input.status === "all" ? undefined : input.status,
},
orderBy: [
Expand Down Expand Up @@ -110,6 +111,7 @@ export const polls = router({
const polls = await prisma.poll.findMany({
where: {
userId: ctx.user.id,
deleted: false,
status: status === "all" ? undefined : status,
},
orderBy: [
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/trpc/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export const user = router({
await prisma.$transaction(async (tx) => {
const polls = await tx.poll.findMany({
select: { id: true },
where: { userId: ctx.user.id },
where: {
userId: ctx.user.id,
},
});
const pollIds = polls.map((poll) => poll.id);

Expand Down
14 changes: 1 addition & 13 deletions packages/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ import { PrismaClient } from "@prisma/client";
export type * from "@prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient().$extends({
query: {
poll: {
findMany: ({ args, query }) => {
if (!args.where?.deleted) {
args.where = { ...args.where, deleted: false };
}

return query(args);
},
},
},
});
return new PrismaClient();
};

export type ExtendedPrismaClient = ReturnType<typeof prismaClientSingleton>;
Expand Down

0 comments on commit 82eb076

Please sign in to comment.