From aa9ce7a23512020137bdeb9701b255a9147ad949 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 9 Dec 2024 20:08:17 +0700 Subject: [PATCH] refactor: remove 'amount' argument from Quiz schema and update quiz retrieval logic - Removed the 'amount' argument from the quiz retrieval query to streamline the schema. - Updated the quiz retrieval logic to use 'nrOfQuestions' from the quiz object instead of the removed 'amount' argument, ensuring consistent behavior in quiz selection. - Improved code clarity by refining comments related to quiz selection logic. --- src/Quiz/quiz.schema.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Quiz/quiz.schema.ts b/src/Quiz/quiz.schema.ts index 70a7ef5..d69d440 100644 --- a/src/Quiz/quiz.schema.ts +++ b/src/Quiz/quiz.schema.ts @@ -155,10 +155,6 @@ export class QuizSchema extends PothosSchema { type: 'String', required: false, }), - amount: t.arg({ - type: 'Int', - required: false, - }), }, resolve: async (query, _root, args, ctx, _info) => { if (ctx.isSubscription) { @@ -186,9 +182,9 @@ export class QuizSchema extends PothosSchema { centerMentorId: centerMentor.mentorId, }, }) - // get amount of quizzes using args.amount and random index based on random + // get amount of quizzes using nrOfQuestions and random index based on random const randomIndex = Math.floor(random * quizzes.length) - return quizzes.slice(randomIndex, randomIndex + (args.amount ?? 1)) + return quizzes.slice(randomIndex, randomIndex + (quizzes[0].nrOfQuestions ?? 1)) } // use case 2: Customer