Moodle Chron wrapped in tryCatch

This commit is contained in:
PxlLoewe
2025-07-11 23:26:01 -07:00
parent d2b287abdc
commit 280393b307

View File

@@ -32,51 +32,55 @@ const syncMoodleIds = async () => {
};
const updateParticipantMoodleResults = async () => {
const participantsMoodlePending = await prisma.participant.findMany({
where: {
finisherMoodleCurseCompleted: false,
Event: {
finisherMoodleCourseId: {
not: null,
try {
const participantsMoodlePending = await prisma.participant.findMany({
where: {
finisherMoodleCurseCompleted: false,
Event: {
finisherMoodleCourseId: {
not: null,
},
},
},
},
include: {
Event: true,
User: true,
},
});
await Promise.all(
participantsMoodlePending.map(async (p) => {
if (!p.User) return;
if (!p.User.moodleId) return;
include: {
Event: true,
User: true,
},
});
await Promise.all(
participantsMoodlePending.map(async (p) => {
if (!p.User) return;
if (!p.User.moodleId) return;
const quizzResult = await getMoodleCourseCompletionStatus(
p.User.moodleId.toString(),
p.Event.finisherMoodleCourseId!,
);
const quizzResult = await getMoodleCourseCompletionStatus(
p.User.moodleId.toString(),
p.Event.finisherMoodleCourseId!,
);
if (quizzResult?.completionstatus?.completed === true) {
await handleParticipantFinished(p.Event, p, p.User);
if (quizzResult?.completionstatus?.completed === true) {
await handleParticipantFinished(p.Event, p, p.User);
return prisma.participant.update({
where: {
id: p.id,
},
data: {
finisherMoodleCurseCompleted: true,
statusLog: {
push: {
event: "Moodle-Kurs abgeschlossen",
timestamp: new Date(),
user: "system",
return prisma.participant.update({
where: {
id: p.id,
},
data: {
finisherMoodleCurseCompleted: true,
statusLog: {
push: {
event: "Moodle-Kurs abgeschlossen",
timestamp: new Date(),
user: "system",
},
},
},
},
});
}
}),
);
});
}
}),
);
} catch (error) {
console.error("Error updating participant Moodle results:", error);
}
};
CronJob.from({ cronTime: "0 * * * *", onTick: syncMoodleIds, start: true });