changed ui package
This commit is contained in:
@@ -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;
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { getMoodleCourseCompletionStatus, getMoodleUserById } from "./moodle";
|
import { getMoodleCourseCompletionStatus, getMoodleUserById } from "./moodle";
|
||||||
import { CronJob } from "cron";
|
import { CronJob } from "cron";
|
||||||
import { prisma } from "@repo/db";
|
import { prisma } from "@repo/db";
|
||||||
import { participantCompleted } from "helper/event";
|
import { eventCompleted } from "@repo/ui/helper";
|
||||||
|
|
||||||
const syncMoodleIds = async () => {
|
const syncMoodleIds = async () => {
|
||||||
try {
|
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: "0 * * * *", onTick: syncMoodleIds, start: true });
|
||||||
CronJob.from({
|
CronJob.from({
|
||||||
cronTime: "*/5 * * * *",
|
cronTime: "*/5 * * * *",
|
||||||
|
|||||||
41
apps/hub-server/modules/event.ts
Normal file
41
apps/hub-server/modules/event.ts
Normal 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",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/index.ts",
|
||||||
|
"./helper": "./src/helper/index.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --max-warnings 0",
|
"lint": "eslint . --max-warnings 0",
|
||||||
|
|||||||
1
packages/ui/src/helper/index.ts
Normal file
1
packages/ui/src/helper/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from "./event";
|
||||||
Reference in New Issue
Block a user