CHanged Event admin layout
This commit is contained in:
@@ -2,6 +2,8 @@ import { getMoodleCourseCompletionStatus, getMoodleUserById } from "./moodle";
|
||||
import { CronJob } from "cron";
|
||||
import { prisma } from "@repo/db";
|
||||
import { eventCompleted } from "@repo/ui/helper";
|
||||
import { sendCourseCompletedEmail } from "modules/mail";
|
||||
import { handleParticipantFinished } from "modules/event";
|
||||
|
||||
const syncMoodleIds = async () => {
|
||||
try {
|
||||
@@ -57,7 +59,7 @@ const updateParticipantMoodleResults = async () => {
|
||||
);
|
||||
|
||||
if (quizzResult?.completionstatus?.completed === true) {
|
||||
await prisma.participant.update({
|
||||
return prisma.participant.update({
|
||||
where: {
|
||||
id: p.id,
|
||||
},
|
||||
@@ -65,7 +67,7 @@ const updateParticipantMoodleResults = async () => {
|
||||
finisherMoodleCurseCompleted: true,
|
||||
statusLog: {
|
||||
push: {
|
||||
event: "Finisher course completed",
|
||||
event: "Moodle-Kurs abgeschlossen",
|
||||
timestamp: new Date(),
|
||||
user: "system",
|
||||
},
|
||||
@@ -77,33 +79,40 @@ const updateParticipantMoodleResults = async () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const checkedFinishedParticipants = async () => {
|
||||
export const checkFinishedParticipants = async () => {
|
||||
console.log("Checking finished participants");
|
||||
const participantsPending = await prisma.participant.findMany({
|
||||
where: {
|
||||
finished: false,
|
||||
completetionWorkflowFinished: false,
|
||||
},
|
||||
include: {
|
||||
Event: true,
|
||||
User: true,
|
||||
},
|
||||
});
|
||||
|
||||
participantsPending.forEach(async (p) => {
|
||||
if (!p.User) return;
|
||||
if (!p.User.moodleId) return;
|
||||
|
||||
const completed = eventCompleted(p.Event, p);
|
||||
|
||||
if (!completed) return;
|
||||
handleParticipantFinished(p.Event, p, p.User);
|
||||
});
|
||||
};
|
||||
|
||||
CronJob.from({ cronTime: "0 * * * *", onTick: syncMoodleIds, start: true });
|
||||
CronJob.from({
|
||||
cronTime: "*/5 * * * *",
|
||||
cronTime: "*/1 * * * *",
|
||||
onTick: async () => {
|
||||
console.log("Updating participant moodle results");
|
||||
await updateParticipantMoodleResults();
|
||||
await checkFinishedParticipants();
|
||||
},
|
||||
start: true,
|
||||
});
|
||||
|
||||
updateParticipantMoodleResults();
|
||||
const debug = async () => {
|
||||
await updateParticipantMoodleResults();
|
||||
await checkFinishedParticipants();
|
||||
};
|
||||
|
||||
debug();
|
||||
|
||||
Reference in New Issue
Block a user