improved gen

This commit is contained in:
Daniel Bulant 2026-05-13 11:27:32 +02:00
parent 93861bb7ce
commit aaff97aeb1
No known key found for this signature in database
4 changed files with 19 additions and 14 deletions

View file

@ -13,7 +13,7 @@ import {
export function buildAudioMetadataQuestion(
analytics: PartyAnalytics,
index: number,
): Question {
): Question | null {
type ChoiceQuestion = Extract<Question, { type: "choice" }>;
const questions: Array<
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
@ -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];

View file

@ -113,7 +113,7 @@ async function countFavouriteArtistListeners({
export async function buildNumericQuestion(
input: BuildNumericQuestionInput,
): Promise<Question> {
): Promise<Question|null> {
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);
}

View file

@ -22,13 +22,18 @@ export async function generatePartyQuestion({
quizState,
analytics,
index,
}: GenerateQuestionInput): Promise<Question> {
}: GenerateQuestionInput): Promise<Question | null> {
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);
}

View file

@ -19,7 +19,7 @@ export function buildSocialQuestion(
analytics: PartyAnalytics,
members: PartyQuestionMember[],
index: number,
): Question {
): Question | null {
type ChoiceQuestion = Extract<Question, { type: "choice" }>;
const questions: Array<
Omit<ChoiceQuestion, "startTimestamp" | "endTimestamp">
@ -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];