From 86dcf15605111666f7ba3ab39ddeaf8a0cd6a4f0 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Tue, 24 Jun 2025 23:11:41 -0700 Subject: [PATCH] =?UTF-8?q?Moodle-=C3=BCberpr=C3=BCfungs=20option=20f?= =?UTF-8?q?=C3=BCr=20admins=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hub-server/routes/event.ts | 38 +++++++ .../event/_components/ParticipantModal.tsx | 107 ++++++++++++------ apps/hub/helper/events.ts | 5 + 3 files changed, 113 insertions(+), 37 deletions(-) diff --git a/apps/hub-server/routes/event.ts b/apps/hub-server/routes/event.ts index 36e37466..53018cf3 100644 --- a/apps/hub-server/routes/event.ts +++ b/apps/hub-server/routes/event.ts @@ -2,6 +2,7 @@ import { prisma } from "@repo/db"; import { Router } from "express"; import { eventCompleted } from "helper/events"; import { handleParticipantEnrolled, handleParticipantFinished } from "modules/event"; +import { getMoodleCourseCompletionStatus } from "modules/moodle"; const router: Router = Router(); @@ -38,6 +39,43 @@ router.post("/handle-participant-finished", async (req, res) => { res.status(200).json({ message: "Participant finished successfully" }); }); +router.post("/check-moodle-results", async (req, res) => { + const { participantId } = req.body; + if (!participantId) { + res.status(400).json({ error: "Participant ID is required" }); + return; + } + const participant = await prisma.participant.findUnique({ + where: { + id: typeof participantId == "string" ? parseInt(participantId) : participantId, + }, + include: { + Event: true, + User: true, + }, + }); + if (!participant) { + res.status(404).json({ error: "Teilnehmer nicht gefunden" }); + return; + } + if (!participant.User || !participant.User.moodleId) { + res.status(400).json({ error: "Teilnehmer hat keine Moodle-ID" }); + return; + } + const quizzResult = await getMoodleCourseCompletionStatus( + participant.User.moodleId.toString(), + participant.Event.finisherMoodleCourseId!, + ); + if (quizzResult?.completionstatus?.completed === true) { + await handleParticipantFinished(participant.Event, participant, participant.User); + res + .status(200) + .json({ message: "Nutzer hat das Moodle-event abgeschlossen, workflow ausgeführt" }); + } else { + res.status(200).json({ message: "Nutzer hat das Moodle-event noch nicht abgeschlossen" }); + } +}); + router.post("/handle-participant-enrolled", async (req, res) => { const { participantId } = req.body; if (!participantId) { diff --git a/apps/hub/app/(app)/admin/event/_components/ParticipantModal.tsx b/apps/hub/app/(app)/admin/event/_components/ParticipantModal.tsx index c548b618..e3c4d1be 100644 --- a/apps/hub/app/(app)/admin/event/_components/ParticipantModal.tsx +++ b/apps/hub/app/(app)/admin/event/_components/ParticipantModal.tsx @@ -5,7 +5,7 @@ import { UseFormReturn } from "react-hook-form"; import { upsertParticipant } from "../../../events/actions"; import { RefObject } from "react"; import { deleteParticipant } from "../action"; -import { handleParticipantFinished } from "../../../../../helper/events"; +import { checkMoodleResults, handleParticipantFinished } from "../../../../../helper/events"; import { AxiosError } from "axios"; import toast from "react-hot-toast"; @@ -22,6 +22,7 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps

Teilnehmer bearbeiten

+
{ await upsertParticipant({ @@ -33,27 +34,6 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps })} className="space-y-1" > - +
+

Debug

+ +
+ + +
+

Termine

@@ -79,21 +110,23 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
))} - - +
+ + +
diff --git a/apps/hub/helper/events.ts b/apps/hub/helper/events.ts index ad9bc190..3668de49 100644 --- a/apps/hub/helper/events.ts +++ b/apps/hub/helper/events.ts @@ -13,6 +13,11 @@ export const handleParticipantFinished = async (participantId: string) => participantId, }); +export const checkMoodleResults = async (participantId: string) => + axios.post(`${process.env.NEXT_PUBLIC_HUB_SERVER_URL}/event/check-moodle-results`, { + participantId, + }); + export const handleParticipantEnrolled = async (participantId: string) => axios.post(`${process.env.NEXT_PUBLIC_HUB_SERVER_URL}/event/handle-participant-enrolled`, { participantId,