Moodle-überprüfungs option für admins hinzugefügt

This commit is contained in:
PxlLoewe
2025-06-24 23:11:41 -07:00
parent d23ea67321
commit 86dcf15605
3 changed files with 113 additions and 37 deletions

View File

@@ -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) {

View File

@@ -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
<button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button>
</form>
<h1 className="text-2xl">Teilnehmer bearbeiten</h1>
<form
onSubmit={participantForm.handleSubmit(async (data) => {
await upsertParticipant({
@@ -33,7 +34,19 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
})}
className="space-y-1"
>
<Switch form={participantForm} name="attended" label="Termin Teilgenommen" />
<Switch form={participantForm} name="appointmentCancelled" label="Termin abgesagt" />
<Switch
form={participantForm}
name="finisherMoodleCurseCompleted"
label="Abschluss-Moodle-Kurs abgeschlossen"
/>
<div>
<h3 className="text-xl">Debug</h3>
<div className="flex gap-3">
<Button
className="btn-sm"
onClick={async () => {
if (!participantForm.watch("id")) return;
@@ -49,18 +62,36 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
} else {
toast.error("Unbekannter Fehler beim ausführen des Workflows");
}
toast.success("Workflow erfolgreich ausgeführt");
});
}}
>
Event-abgeschlossen Workflow ausführen
</Button>
<Switch form={participantForm} name="attended" label="Termin Teilgenommen" />
<Switch form={participantForm} name="appointmentCancelled" label="Termin abgesagt" />
<Switch
form={participantForm}
name="finisherMoodleCurseCompleted"
label="Abschluss-Moodle-Kurs abgeschlossen"
/>
<Button
className="btn-sm"
onClick={async () => {
if (!participantForm.watch("id")) return;
const participant = participantForm.getValues();
await checkMoodleResults(participant.id.toString()).catch((e) => {
const error = e as AxiosError;
if (
error.response?.data &&
typeof error.response.data === "object" &&
"error" in error.response.data
) {
toast.error(`Fehler: ${error.response.data.error}`);
} else {
toast.error("Unbekannter Fehler beim ausführen des Workflows");
}
});
}}
>
Moodle-Kurs aktualisieren
</Button>
</div>
</div>
<div className="w-full">
<h3 className="text-xl">Termine</h3>
@@ -79,6 +110,7 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
</div>
))}
</div>
<div className="flex gap-2 w-full justify-center">
<Button type="submit" className="btn btn-primary">
Speichern
</Button>
@@ -94,6 +126,7 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
>
Löschen
</Button>
</div>
</form>
</div>
</dialog>

View File

@@ -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,