Files
var-monorepo/apps/hub/app/(app)/events/actions.ts
2025-03-01 00:31:03 +01:00

33 lines
702 B
TypeScript

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