mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-30 10:46:35 +02:00
🐛 Fix can’t delete user with deleted polls
This commit is contained in:
parent
501cdd2b56
commit
c8cb3b3855
3 changed files with 6 additions and 14 deletions
|
@ -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: [
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue