From ceeeff96816bef0c526addc826e0a839e0db2211 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Fri, 3 Jun 2022 16:54:45 +0300 Subject: [PATCH] fix: metaculus on groups --- src/backend/platforms/metaculus/api.ts | 6 +++--- src/backend/platforms/metaculus/index.ts | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/platforms/metaculus/api.ts b/src/backend/platforms/metaculus/api.ts index 760b6b0..d8e2ad8 100644 --- a/src/backend/platforms/metaculus/api.ts +++ b/src/backend/platforms/metaculus/api.ts @@ -106,6 +106,9 @@ const questionSchema = { properties: { ...commonProps, ...pageProps, + }, + optionalProperties: { + ...optionalPageProps, sub_questions: { elements: { properties: { @@ -116,9 +119,6 @@ const questionSchema = { }, }, }, - optionalProperties: { - ...optionalPageProps, - }, additionalProperties: true, }, // we're not interested in claims currently (but we should be?) diff --git a/src/backend/platforms/metaculus/index.ts b/src/backend/platforms/metaculus/index.ts index 526fca6..8dbfd63 100644 --- a/src/backend/platforms/metaculus/index.ts +++ b/src/backend/platforms/metaculus/index.ts @@ -74,7 +74,10 @@ async function apiQuestionToFetchedQuestions( if (apiQuestion.type === "group") { await sleep(SLEEP_TIME); const apiQuestionDetails = await fetchSingleApiQuestion(apiQuestion.id); - return apiQuestion.sub_questions + if (apiQuestionDetails.type !== "group") { + throw new Error("Expected `group` type"); // shouldn't happen, this is mostly for typescript + } + return (apiQuestionDetails.sub_questions || []) .filter((q) => !skip(q)) .map((sq) => { const tmp = buildFetchedQuestion(sq);