Moodle-überprüfungs option für admins hinzugefügt
This commit is contained in:
@@ -2,6 +2,7 @@ import { prisma } from "@repo/db";
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { eventCompleted } from "helper/events";
|
import { eventCompleted } from "helper/events";
|
||||||
import { handleParticipantEnrolled, handleParticipantFinished } from "modules/event";
|
import { handleParticipantEnrolled, handleParticipantFinished } from "modules/event";
|
||||||
|
import { getMoodleCourseCompletionStatus } from "modules/moodle";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@@ -38,6 +39,43 @@ router.post("/handle-participant-finished", async (req, res) => {
|
|||||||
res.status(200).json({ message: "Participant finished successfully" });
|
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) => {
|
router.post("/handle-participant-enrolled", async (req, res) => {
|
||||||
const { participantId } = req.body;
|
const { participantId } = req.body;
|
||||||
if (!participantId) {
|
if (!participantId) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { UseFormReturn } from "react-hook-form";
|
|||||||
import { upsertParticipant } from "../../../events/actions";
|
import { upsertParticipant } from "../../../events/actions";
|
||||||
import { RefObject } from "react";
|
import { RefObject } from "react";
|
||||||
import { deleteParticipant } from "../action";
|
import { deleteParticipant } from "../action";
|
||||||
import { handleParticipantFinished } from "../../../../../helper/events";
|
import { checkMoodleResults, handleParticipantFinished } from "../../../../../helper/events";
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import toast from "react-hot-toast";
|
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>
|
<button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
||||||
</form>
|
</form>
|
||||||
<h1 className="text-2xl">Teilnehmer bearbeiten</h1>
|
<h1 className="text-2xl">Teilnehmer bearbeiten</h1>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
onSubmit={participantForm.handleSubmit(async (data) => {
|
onSubmit={participantForm.handleSubmit(async (data) => {
|
||||||
await upsertParticipant({
|
await upsertParticipant({
|
||||||
@@ -33,7 +34,19 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
|||||||
})}
|
})}
|
||||||
className="space-y-1"
|
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
|
<Button
|
||||||
|
className="btn-sm"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (!participantForm.watch("id")) return;
|
if (!participantForm.watch("id")) return;
|
||||||
|
|
||||||
@@ -49,18 +62,36 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
|||||||
} else {
|
} else {
|
||||||
toast.error("Unbekannter Fehler beim ausführen des Workflows");
|
toast.error("Unbekannter Fehler beim ausführen des Workflows");
|
||||||
}
|
}
|
||||||
|
toast.success("Workflow erfolgreich ausgeführt");
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Event-abgeschlossen Workflow ausführen
|
Event-abgeschlossen Workflow ausführen
|
||||||
</Button>
|
</Button>
|
||||||
<Switch form={participantForm} name="attended" label="Termin Teilgenommen" />
|
<Button
|
||||||
<Switch form={participantForm} name="appointmentCancelled" label="Termin abgesagt" />
|
className="btn-sm"
|
||||||
<Switch
|
onClick={async () => {
|
||||||
form={participantForm}
|
if (!participantForm.watch("id")) return;
|
||||||
name="finisherMoodleCurseCompleted"
|
|
||||||
label="Abschluss-Moodle-Kurs abgeschlossen"
|
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">
|
<div className="w-full">
|
||||||
<h3 className="text-xl">Termine</h3>
|
<h3 className="text-xl">Termine</h3>
|
||||||
|
|
||||||
@@ -79,6 +110,7 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex gap-2 w-full justify-center">
|
||||||
<Button type="submit" className="btn btn-primary">
|
<Button type="submit" className="btn btn-primary">
|
||||||
Speichern
|
Speichern
|
||||||
</Button>
|
</Button>
|
||||||
@@ -94,6 +126,7 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
|||||||
>
|
>
|
||||||
Löschen
|
Löschen
|
||||||
</Button>
|
</Button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ export const handleParticipantFinished = async (participantId: string) =>
|
|||||||
participantId,
|
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) =>
|
export const handleParticipantEnrolled = async (participantId: string) =>
|
||||||
axios.post(`${process.env.NEXT_PUBLIC_HUB_SERVER_URL}/event/handle-participant-enrolled`, {
|
axios.post(`${process.env.NEXT_PUBLIC_HUB_SERVER_URL}/event/handle-participant-enrolled`, {
|
||||||
participantId,
|
participantId,
|
||||||
|
|||||||
Reference in New Issue
Block a user