From aaff97aeb172783cb4046c08bfb197fbf2827598 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Wed, 13 May 2026 11:27:32 +0200 Subject: [PATCH] improved gen --- api/src/party/audio-question-generator.ts | 6 +++--- api/src/party/numeric-question-generator.ts | 4 ++-- api/src/party/question-generator.ts | 17 +++++++++++------ api/src/party/social-question-generator.ts | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/api/src/party/audio-question-generator.ts b/api/src/party/audio-question-generator.ts index f76bb80..573588d 100644 --- a/api/src/party/audio-question-generator.ts +++ b/api/src/party/audio-question-generator.ts @@ -13,7 +13,7 @@ import { export function buildAudioMetadataQuestion( analytics: PartyAnalytics, index: number, -): Question { +): Question | null { type ChoiceQuestion = Extract; const questions: Array< Omit @@ -126,8 +126,8 @@ export function buildAudioMetadataQuestion( } } - if (questions.length === 0) { - throw new Error("Question not found"); + if (questions.length === 0) { + return null } const question = questions[index % questions.length]; diff --git a/api/src/party/numeric-question-generator.ts b/api/src/party/numeric-question-generator.ts index e17d93e..8c61e15 100644 --- a/api/src/party/numeric-question-generator.ts +++ b/api/src/party/numeric-question-generator.ts @@ -113,7 +113,7 @@ async function countFavouriteArtistListeners({ export async function buildNumericQuestion( input: BuildNumericQuestionInput, -): Promise { +): Promise { const questions: NumericQuestion[] = []; questions.push(await getAlbumReleaseYear(input)); @@ -125,6 +125,6 @@ export async function buildNumericQuestion( if (artistQ) questions.push(artistQ); const question = questions[input.index % questions.length] ?? questions[0]; - if (!question) throw new Error("Question not found"); + if (!question) return null; return buildQuestionWindow(question); } diff --git a/api/src/party/question-generator.ts b/api/src/party/question-generator.ts index ea9206f..f6a7d86 100644 --- a/api/src/party/question-generator.ts +++ b/api/src/party/question-generator.ts @@ -22,13 +22,18 @@ export async function generatePartyQuestion({ quizState, analytics, index, -}: GenerateQuestionInput): Promise { +}: GenerateQuestionInput): Promise { const members = await fetchPartyMembers(dbClient, partyId); const type: PartyQuestionType = index === 2 ? "numeric" : index % 2 === 0 ? "audio-metadata" : "social"; - return type === "audio-metadata" - ? buildAudioMetadataQuestion(analytics, index) - : type === "numeric" - ? buildNumericQuestion({ db: dbClient, analytics, index, members }) - : buildSocialQuestion(quizState, analytics, members, index); + + if (type === "audio-metadata") { + let q = buildAudioMetadataQuestion(analytics, index); + if (q) return q; + } + if (type === "numeric") { + let q = await buildNumericQuestion({ db: dbClient, analytics, index, members }); + if (q) return q; + } + return buildSocialQuestion(quizState, analytics, members, index); } diff --git a/api/src/party/social-question-generator.ts b/api/src/party/social-question-generator.ts index 8559c5d..b039fd7 100644 --- a/api/src/party/social-question-generator.ts +++ b/api/src/party/social-question-generator.ts @@ -19,7 +19,7 @@ export function buildSocialQuestion( analytics: PartyAnalytics, members: PartyQuestionMember[], index: number, -): Question { +): Question | null { type ChoiceQuestion = Extract; const questions: Array< Omit @@ -98,8 +98,8 @@ export function buildSocialQuestion( } } - if (questions.length === 0) { - throw new Error("Question not found"); + if (questions.length === 0) { + return null } const question = questions[index % questions.length];