completed Implementation of User Event page
This commit is contained in:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user