completed Implementation of User Event page

This commit is contained in:
PxlLoewe
2025-03-01 00:31:03 +01:00
parent 488c50e2e0
commit daf3238bee
6 changed files with 146 additions and 113 deletions

View File

@@ -1,6 +1,6 @@
"use server";
import { enrollUserInCourse } from "../../../helper/moodle";
import { prisma } from "@repo/db";
import { Prisma, prisma } from "@repo/db";
export const inscribeToMoodleCourse = async (
moodleCourseId: string | number,
@@ -9,18 +9,24 @@ export const inscribeToMoodleCourse = async (
await enrollUserInCourse(moodleCourseId, userMoodleId);
};
export const addParticipant = async (eventId: number, userId: string) => {
export const upsertParticipant = async (
data: Prisma.ParticipantUncheckedCreateInput,
) => {
const participant = await prisma.participant.findFirst({
where: {
userId: userId,
userId: data.userId,
eventId: data.eventId,
},
});
if (!participant) {
await prisma.participant.create({
data: {
userId: userId,
eventId,
},
return await prisma.participant.create({
data,
});
}
return await prisma.participant.update({
where: {
id: participant.id,
},
data,
});
};