changed ui package

This commit is contained in:
PxlLoewe
2025-03-07 14:42:34 -07:00
parent 829e78a47d
commit 6fc20a66ef
5 changed files with 64 additions and 37 deletions

View File

@@ -1,11 +0,0 @@
import { Event, Participant } from "@repo/db";
export const participantCompleted = (
event: Event,
participant: Participant,
) => {
if (event.finisherMoodleCourseId && !participant.finisherMoodleCurseCompleted)
return false;
if (event.hasPresenceEvents && !participant.attended) return false;
return true;
};

View File

@@ -1,7 +1,7 @@
import { getMoodleCourseCompletionStatus, getMoodleUserById } from "./moodle";
import { CronJob } from "cron";
import { prisma } from "@repo/db";
import { participantCompleted } from "helper/event";
import { eventCompleted } from "@repo/ui/helper";
const syncMoodleIds = async () => {
try {
@@ -72,35 +72,30 @@ const updateParticipantMoodleResults = async () => {
},
},
});
if (participantCompleted(p.Event, p)) {
// Event is completed, give relating permissions
await prisma.user.update({
where: {
id: p.userId,
},
data: {
permissions: {
push: p.Event.finishedPermissions,
},
badges: {
push: p.Event.finishedBadges,
},
},
});
await prisma.participant.update({
where: {
id: p.id,
},
data: {
finished: true,
},
});
}
}
}),
);
};
export const checkedFinishedParticipants = async () => {
const participantsPending = await prisma.participant.findMany({
where: {
finished: 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);
});
};
CronJob.from({ cronTime: "0 * * * *", onTick: syncMoodleIds, start: true });
CronJob.from({
cronTime: "*/5 * * * *",

View File

@@ -0,0 +1,41 @@
import { Event, Participant, prisma, User } from "@repo/db";
export const handleParticipantFinished = async (
event: Event,
participant: Participant,
user: User,
) => {
const discordID = prisma.discordAccount.findFirst({
where: {
userId: user.id,
},
});
prisma.user.update({
where: {
id: user.id,
},
data: {
badges: {
push: event.finishedBadges,
},
permissions: event.finishedPermissions,
},
});
prisma.participant.update({
where: {
id: participant.id,
},
data: {
finished: true,
statusLog: {
push: {
event: "Event finished",
timestamp: new Date(),
user: "system",
},
},
},
});
};