From 226dd4062c48c37c97240fb127a9c3c566f4402e Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Sun, 22 Dec 2024 11:36:48 +0100 Subject: [PATCH] Fix ts issues --- apps/web/src/components/poll/mutations.ts | 8 +++++--- apps/web/src/trpc/routers/polls/participants.ts | 5 +---- packages/database/prisma/seed.ts | 6 ++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/poll/mutations.ts b/apps/web/src/components/poll/mutations.ts index 98ea6bdc6..ad040dfc2 100644 --- a/apps/web/src/components/poll/mutations.ts +++ b/apps/web/src/components/poll/mutations.ts @@ -20,13 +20,15 @@ export const useAddParticipantMutation = () => { const queryClient = trpc.useUtils(); return trpc.polls.participants.add.useMutation({ - onSuccess: (newParticipant, input) => { - const { pollId, name, email } = newParticipant; + onSuccess: (res, input) => { + const { poll, ...newParticipant } = res; + const { name, email } = newParticipant; + const pollId = poll.id; queryClient.polls.participants.list.setData( { pollId }, (existingParticipants = []) => { return [ - { ...newParticipant, votes: input.votes }, + { ...newParticipant, votes: input.votes, pollId }, ...existingParticipants, ]; }, diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts index 08a274300..89317237d 100644 --- a/apps/web/src/trpc/routers/polls/participants.ts +++ b/apps/web/src/trpc/routers/polls/participants.ts @@ -112,10 +112,7 @@ export const participants = router({ }, }, }, - select: { - id: true, - name: true, - email: true, + include: { poll: { select: { id: true, diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.ts index 836a72b00..2851f3db9 100644 --- a/packages/database/prisma/seed.ts +++ b/packages/database/prisma/seed.ts @@ -63,6 +63,12 @@ async function createPollForUser(userId: string) { () => ({ name: faker.name.fullName(), email: faker.internet.email(), + user: { + create: { + id: faker.random.alpha(10), + isGuest: true, + }, + }, }), ), },