diff --git a/core/api/src/app/quiz/add.ts b/core/api/src/app/quiz/add.ts index c163c0dddb9..f289c1cd2b4 100644 --- a/core/api/src/app/quiz/add.ts +++ b/core/api/src/app/quiz/add.ts @@ -51,9 +51,9 @@ export const completeQuiz = async ({ const quizzesConfig = getQuizzesConfig() // TODO: quizQuestionId checkedFor - const quizQuestionId = quizQuestionIdString as QuizQuestionId + const quizId = quizQuestionIdString as QuizQuestionId - const amount = QuizzesValue[quizQuestionId] + const amount = QuizzesValue[quizId] if (!amount) return new InvalidQuizQuestionIdError() const funderWalletId = await getFunderWalletId() @@ -100,7 +100,7 @@ export const completeQuiz = async ({ if (recipientBtcWallet === undefined) return new NoBtcWalletExistsForAccountError() const recipientWalletId = recipientBtcWallet.id - const shouldGiveSats = await QuizRepository(accountId).add(quizQuestionId) + const shouldGiveSats = await QuizRepository().add({ quizId, accountId }) if (shouldGiveSats instanceof Error) return shouldGiveSats const funderBalance = await getBalanceForWallet({ walletId: funderWalletId }) @@ -116,12 +116,12 @@ export const completeQuiz = async ({ senderWalletId: funderWalletId, recipientWalletId, amount, - memo: quizQuestionId, + memo: quizId, senderAccount: funderAccount, }) if (payment instanceof Error) return payment - return { id: quizQuestionId, earnAmount: amount } + return { id: quizId, earnAmount: amount } } const checkAddQuizAttemptPerIpLimits = async ( diff --git a/core/api/src/app/quiz/get.ts b/core/api/src/app/quiz/get.ts index e410b6ac38c..356e0e01938 100644 --- a/core/api/src/app/quiz/get.ts +++ b/core/api/src/app/quiz/get.ts @@ -2,7 +2,7 @@ import { QuizzesValue } from "@/domain/earn/config" import { QuizRepository } from "@/services/mongoose" export const getQuizzesByAccountId = async (accountId: AccountId) => { - const quizzes = await QuizRepository(accountId).fetchAll() + const quizzes = await QuizRepository().fetchAll(accountId) if (quizzes instanceof Error) return quizzes const solvedQuizId = quizzes.map((quiz) => quiz.quizId) diff --git a/core/api/src/services/mongoose/quiz.ts b/core/api/src/services/mongoose/quiz.ts index b7e4aae092e..1bd8cec8311 100644 --- a/core/api/src/services/mongoose/quiz.ts +++ b/core/api/src/services/mongoose/quiz.ts @@ -6,8 +6,14 @@ interface ExtendedError extends Error { code?: number } -export const QuizRepository = (accountId: AccountId) => { - const add = async (quizId: QuizQuestionId) => { +export const QuizRepository = () => { + const add = async ({ + quizId, + accountId, + }: { + quizId: QuizQuestionId + accountId: AccountId + }) => { try { await Quiz.create({ accountId, quizId }) @@ -22,7 +28,7 @@ export const QuizRepository = (accountId: AccountId) => { } } - const fetchAll = async () => { + const fetchAll = async (accountId: AccountId) => { try { const result = await Quiz.find({ accountId }) return result diff --git a/core/api/test/integration/services/quiz.spec.ts b/core/api/test/integration/services/quiz.spec.ts index b6fe7abe676..d3b329d5929 100644 --- a/core/api/test/integration/services/quiz.spec.ts +++ b/core/api/test/integration/services/quiz.spec.ts @@ -5,32 +5,32 @@ import { QuizRepository } from "@/services/mongoose" describe("QuizRepository", () => { const accountId = crypto.randomUUID() as AccountId - const quizQuestionId = "fakeQuizQuestionId" as QuizQuestionId + const quizId = "fakeQuizQuestionId" as QuizQuestionId it("add quiz", async () => { - const result = await QuizRepository(accountId).add(quizQuestionId) + const result = await QuizRepository().add({ quizId, accountId }) expect(result).toBe(true) }) it("can't add quiz twice", async () => { - const result = await QuizRepository(accountId).add(quizQuestionId) + const result = await QuizRepository().add({ quizId, accountId }) expect(result).toBeInstanceOf(QuizAlreadyPresentError) }) it("fetch quiz", async () => { - const result = await QuizRepository(accountId).fetchAll() + const result = await QuizRepository().fetchAll(accountId) expect(result).toHaveLength(1) }) it("fetch quizzes", async () => { const quiz2 = "fakeQuizQuestionId2" as QuizQuestionId - await QuizRepository(accountId).add(quiz2) + await QuizRepository().add({ accountId, quizId: quiz2 }) - const result = await QuizRepository(accountId).fetchAll() + const result = await QuizRepository().fetchAll(accountId) expect(result).toMatchObject([ { accountId, - quizId: quizQuestionId, + quizId: quizId, }, { accountId,