Moodle Chron wrapped in tryCatch
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user