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 { 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) {
|
||||
|
||||
@@ -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,27 +34,6 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
||||
})}
|
||||
className="space-y-1"
|
||||
>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
if (!participantForm.watch("id")) return;
|
||||
|
||||
const participant = participantForm.getValues();
|
||||
await handleParticipantFinished(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");
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
Event-abgeschlossen Workflow ausführen
|
||||
</Button>
|
||||
<Switch form={participantForm} name="attended" label="Termin Teilgenommen" />
|
||||
<Switch form={participantForm} name="appointmentCancelled" label="Termin abgesagt" />
|
||||
<Switch
|
||||
@@ -61,6 +41,57 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
||||
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;
|
||||
|
||||
const participant = participantForm.getValues();
|
||||
await handleParticipantFinished(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");
|
||||
}
|
||||
toast.success("Workflow erfolgreich ausgeführt");
|
||||
});
|
||||
}}
|
||||
>
|
||||
Event-abgeschlossen Workflow ausführen
|
||||
</Button>
|
||||
<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,21 +110,23 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Button type="submit" className="btn btn-primary">
|
||||
Speichern
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
className="btn btn-error btn-outline"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
deleteParticipant(participantForm.watch("id"));
|
||||
participantForm.reset();
|
||||
ref.current?.close();
|
||||
}}
|
||||
>
|
||||
Löschen
|
||||
</Button>
|
||||
<div className="flex gap-2 w-full justify-center">
|
||||
<Button type="submit" className="btn btn-primary">
|
||||
Speichern
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
className="btn btn-error btn-outline"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
deleteParticipant(participantForm.watch("id"));
|
||||
participantForm.reset();
|
||||
ref.current?.close();
|
||||
}}
|
||||
>
|
||||
Löschen
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user