From e117969b79bee870fd66f02d786cd12cdc0be5f3 Mon Sep 17 00:00:00 2001 From: Muktazam Hasbi Ashidiqi Date: Wed, 17 Apr 2024 09:50:13 +0700 Subject: [PATCH] fix: check participation before registering to a quiz --- app/lib/services/quiz_service.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/lib/services/quiz_service.dart b/app/lib/services/quiz_service.dart index 1f737c0..ee789b0 100644 --- a/app/lib/services/quiz_service.dart +++ b/app/lib/services/quiz_service.dart @@ -40,9 +40,24 @@ class QuizService { Future registerParticipant(String week, String level) async { final levelLowerCase = level.toLowerCase(); final snapshot = await db.collection('configuration').doc(week).get(); + + final checkParticipation = await db + .collection('weekly_quiz_participation') + .where( + 'quiz_id', + isEqualTo: snapshot['id'], + ) + .where( + 'user_uid', + isEqualTo: currentUserUID, + ) + .get(); + if (checkParticipation.docs.isNotEmpty) { + return; + } + final registeredUserSnapshot = await db.collection('registered_user').doc(currentUserUID).get(); - // background task untuk fetch task untuk sesuai minggu dan level // yang akan didaftarkan agar bisa dipakai offline // for (final taskId in snapshot['tasks'][level] as List) {