removed event-chronjobs, used Events in hub-app insteand, added admin Btn to set Discord-User and run Event-completed-workflow. Fixed Bug of wrong participants-count in Event-Modal
This commit is contained in:
72
apps/hub-server/routes/event.ts
Normal file
72
apps/hub-server/routes/event.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { prisma } from "@repo/db";
|
||||
import { Router } from "express";
|
||||
import { eventCompleted } from "helper/events";
|
||||
import { handleParticipantEnrolled, handleParticipantFinished } from "modules/event";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
router.post("/handle-participant-finished", async (req, res) => {
|
||||
const { participantId } = req.body;
|
||||
if (!participantId) {
|
||||
res.status(400).json({ error: "Participant ID is required" });
|
||||
return;
|
||||
}
|
||||
const participant = await prisma.participant.findUnique({
|
||||
where: {
|
||||
id: typeof participantId == "string" ? parseInt(participantId) : participantId,
|
||||
},
|
||||
include: {
|
||||
Event: true,
|
||||
User: {
|
||||
include: {
|
||||
discordAccounts: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!participant) {
|
||||
res.status(404).json({ error: "Participant not found" });
|
||||
return;
|
||||
}
|
||||
const completed = eventCompleted(participant.Event, participant);
|
||||
if (!completed) {
|
||||
res.status(400).json({ error: "Event not completed" });
|
||||
return;
|
||||
}
|
||||
await handleParticipantFinished(participant.Event, participant, participant.User);
|
||||
res.status(200).json({ message: "Participant finished successfully" });
|
||||
});
|
||||
|
||||
router.post("/handle-participant-enrolled", async (req, res) => {
|
||||
const { participantId } = req.body;
|
||||
if (!participantId) {
|
||||
res.status(400).json({ error: "Participant ID is required" });
|
||||
return;
|
||||
}
|
||||
const participant = await prisma.participant.findUnique({
|
||||
where: {
|
||||
id: typeof participantId == "string" ? parseInt(participantId) : participantId,
|
||||
},
|
||||
include: {
|
||||
Event: true,
|
||||
User: {
|
||||
include: {
|
||||
discordAccounts: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!participant) {
|
||||
res.status(404).json({ error: "Participant not found" });
|
||||
return;
|
||||
}
|
||||
const completed = eventCompleted(participant.Event, participant);
|
||||
if (completed) {
|
||||
res.status(400).json({ error: "Event already completed" });
|
||||
return;
|
||||
}
|
||||
await handleParticipantEnrolled(participant.Event, participant, participant.User);
|
||||
res.status(200).json({ message: "Participant enrolled successfully" });
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user