fixed moodle logic

This commit is contained in:
PxlLoewe
2025-06-26 13:40:33 -07:00
parent 8968bff1c5
commit 22a406c2d1
13 changed files with 127 additions and 95 deletions

View File

@@ -1,7 +1,8 @@
HUB_SERVER_PORT=3003
MOODLE_TOKEN=ac346f0324647b68488d13fd52a9bbe8
MOODLE_API_TOKEN=ac346f0324647b68488d13fd52a9bbe8
NEXT_PUBLIC_HUB_URL=http://localhost:3000
MOODLE_URL=http://localhost:8081
NEXT_PUBLIC_MOODLE_URL=
MAIL_SERVER="asmtp.mail.hostpoint.ch"
MAIL_USER="noreply@virtualairrescue.com"
MAIL_PASSWORD="b7316PB8aDPCC%-&"

View File

@@ -4,8 +4,12 @@ export const getMoodleUserById = async (id: string) => {
const { data: user } = await axios.get(
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
{
auth: {
username: "moodleuser",
password: "Xo1SXaLYBa7Yb6WW",
},
params: {
wstoken: process.env.MOODLE_TOKEN,
wstoken: process.env.MOODLE_API_TOKEN,
wsfunction: "core_user_get_users_by_field",
moodlewsrestformat: "json",
field: "idnumber",
@@ -33,8 +37,12 @@ export const getMoodleQuizResult = async (userId: string, quizId: string) => {
const { data: quizzes } = await axios.get(
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
{
auth: {
username: "moodleuser",
password: "Xo1SXaLYBa7Yb6WW",
},
params: {
wstoken: process.env.MOODLE_TOKEN,
wstoken: process.env.MOODLE_API_TOKEN,
wsfunction: "mod_quiz_get_user_attempts",
moodlewsrestformat: "json",
quizid: quizId,
@@ -49,8 +57,12 @@ export const getMoodleCourseCompletionStatus = async (userId: string, courseId:
const { data: completionStatus } = await axios.get(
`${process.env.NEXT_PUBLIC_MOODLE_URL}/webservice/rest/server.php`,
{
auth: {
username: "moodleuser",
password: "Xo1SXaLYBa7Yb6WW",
},
params: {
wstoken: process.env.MOODLE_TOKEN,
wstoken: process.env.MOODLE_API_TOKEN,
wsfunction: "core_completion_get_course_completion_status",
moodlewsrestformat: "json",
userid: userId,

View File

@@ -25,7 +25,6 @@ router.post("/handle-participant-finished", async (req, res) => {
},
},
});
console.log("Handeling Participant-completed", participant?.User.publicId);
if (!participant) {
res.status(404).json({ error: "Participant not found" });
return;
@@ -62,11 +61,16 @@ router.post("/check-moodle-results", async (req, res) => {
res.status(400).json({ error: "Teilnehmer hat keine Moodle-ID" });
return;
}
const quizzResult = await getMoodleCourseCompletionStatus(
const courseStatus = await getMoodleCourseCompletionStatus(
participant.User.moodleId.toString(),
participant.Event.finisherMoodleCourseId!,
);
if (quizzResult?.completionstatus?.completed === true) {
if (courseStatus?.completionstatus?.completed === true) {
prisma.participant.update({
where: { id: participant.id },
data: { finisherMoodleCurseCompleted: true },
});
await handleParticipantFinished(participant.Event, participant, participant.User);
res
.status(200)