🐛 Fix can’t delete user with deleted polls

This commit is contained in:
Luke Vella 2024-10-20 20:54:27 +01:00
parent 501cdd2b56
commit c8cb3b3855
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
3 changed files with 6 additions and 14 deletions

View file

@ -70,6 +70,7 @@ export const polls = router({
return await prisma.poll.findMany({ return await prisma.poll.findMany({
where: { where: {
userId: ctx.user.id, userId: ctx.user.id,
deleted: false,
status: input.status === "all" ? undefined : input.status, status: input.status === "all" ? undefined : input.status,
}, },
orderBy: [ orderBy: [
@ -110,6 +111,7 @@ export const polls = router({
const polls = await prisma.poll.findMany({ const polls = await prisma.poll.findMany({
where: { where: {
userId: ctx.user.id, userId: ctx.user.id,
deleted: false,
status: status === "all" ? undefined : status, status: status === "all" ? undefined : status,
}, },
orderBy: [ orderBy: [

View file

@ -56,7 +56,9 @@ export const user = router({
await prisma.$transaction(async (tx) => { await prisma.$transaction(async (tx) => {
const polls = await tx.poll.findMany({ const polls = await tx.poll.findMany({
select: { id: true }, select: { id: true },
where: { userId: ctx.user.id }, where: {
userId: ctx.user.id,
},
}); });
const pollIds = polls.map((poll) => poll.id); const pollIds = polls.map((poll) => poll.id);

View file

@ -3,19 +3,7 @@ import { PrismaClient } from "@prisma/client";
export type * from "@prisma/client"; export type * from "@prisma/client";
const prismaClientSingleton = () => { const prismaClientSingleton = () => {
return new PrismaClient().$extends({ return new PrismaClient();
query: {
poll: {
findMany: ({ args, query }) => {
if (!args.where?.deleted) {
args.where = { ...args.where, deleted: false };
}
return query(args);
},
},
},
});
}; };
export type ExtendedPrismaClient = ReturnType<typeof prismaClientSingleton>; export type ExtendedPrismaClient = ReturnType<typeof prismaClientSingleton>;