From 1e9af1ae37dfd7fe2b162bda1001fb00700de02a Mon Sep 17 00:00:00 2001 From: Ariaspect Date: Wed, 16 Aug 2023 15:56:01 +0900 Subject: [PATCH 1/2] refactor(interface): simplify voted --- interface/admin/agenda/server.ts | 7 ++----- interface/agenda/server.ts | 8 +------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/interface/admin/agenda/server.ts b/interface/admin/agenda/server.ts index 6613ef5a..5753ec21 100644 --- a/interface/admin/agenda/server.ts +++ b/interface/admin/agenda/server.ts @@ -42,10 +42,7 @@ export type Deleted = z.infer; */ export const Voted = z.object({ id: z.number(), - // choices: z.array(AdminChoice), - voters: z.object({ - voted: z.array(User), - total: z.array(User), - }), + voted: z.number(), + user: User, }); export type Voted = z.infer; diff --git a/interface/agenda/server.ts b/interface/agenda/server.ts index a2c822b9..0a4f5edc 100644 --- a/interface/agenda/server.ts +++ b/interface/agenda/server.ts @@ -14,13 +14,7 @@ export type Started = z.infer; */ export const Voted = z.object({ id: z.number(), - user: z.object({ - voted: z.number(), - }), - voters: z.object({ - voted: z.number(), - total: z.number(), - }), + voted: z.number(), }); export type Voted = z.infer; From 63e71889a19891e4f00a22fc75a6ed56e2992416 Mon Sep 17 00:00:00 2001 From: Ariaspect Date: Wed, 16 Aug 2023 15:57:09 +0900 Subject: [PATCH 2/2] refactor(agenda): simplify voted emit --- server/src/service/agenda.ts | 53 ++---------------------------------- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/server/src/service/agenda.ts b/server/src/service/agenda.ts index 64411c0a..32979835 100644 --- a/server/src/service/agenda.ts +++ b/server/src/service/agenda.ts @@ -115,61 +115,14 @@ export const vote = async ( userId: user.id, choiceId: choiceId, }, - select: { - choice: { - select: { - agenda: { - select: { - choices: { - select: { - users: { - select: { - user: { - select: { - id: true, - username: true, - displayName: true, - }, - }, - }, - }, - }, - }, - voters: { - select: { - user: { - select: { - id: true, - username: true, - displayName: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, }); io.emit("agenda.voted", { id: agendaId, - user: { - voted: choiceId, - }, - voters: { - voted: res.choice.agenda.choices.reduce( - (acc, choice) => acc + choice.users.length, - 0, - ), - total: res.choice.agenda.voters.length, - }, + voted: choiceId, }); io.emit("admin.agenda.voted", { id: agendaId, - voters: { - voted: res.choice.agenda.choices.flatMap(c => c.users.map(u => u.user)), - total: res.choice.agenda.voters.flatMap(v => v.user), - }, + voted: choiceId, + user: user, }); };