Skip to content

Commit

Permalink
ajout file (#12)
Browse files Browse the repository at this point in the history
revert deletion
  • Loading branch information
demanguillaume authored Jun 24, 2024
1 parent a877a22 commit 5ed9931
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/repositories/eventUserStepRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import prisma from "@/lib/prisma";
import { EventUserStepWithoutId } from "@/types/eventUserStep";
import { EventUserStep } from "@prisma/client";

/**
* @params data: EventUserStepWithoutId
* @returns EventUserStep
* @description Creates a new user step event with the provided data.
*/
export const createEventUserStep = async (
data: EventUserStepWithoutId,
): Promise<EventUserStep> => {
return await prisma.eventUserStep.create({
data,
});
};

/**
* @params id: number
* @returns EventUserStep | null
* @description Retrieves a user step event by its id.
*/
export const readEventUserStep = async (
id: number,
): Promise<EventUserStep | null> => {
return await prisma.eventUserStep.findUnique({ where: { id } });
};

/**
* @params userId: number
* @params eventId: number
* @params stepId: number
* @returns EventUserStep | null
* @description Retrieves a user step event by user id, event id, and step id.
*/
export const readEventUserStepByIds = async (
userId: number,
eventId: number,
stepId: number,
): Promise<EventUserStep | null> => {
return await prisma.eventUserStep.findFirst({
where: { userId, eventId, stepId },
});
};

/**
* @returns EventUserStep[]
* @description Retrieves all user step events.
*/
export const readEventUserSteps = async (): Promise<EventUserStep[]> => {
return await prisma.eventUserStep.findMany();
};

/**
* @params userId: number
* @params eventId: number
* @returns EventUserStep[]
* @description Retrieves all user step events for a given user and event.
*/
export const readEventUserStepsByUserIdAndEventId = async (
userId: number,
eventId: number,
): Promise<EventUserStep[]> => {
return await prisma.eventUserStep.findMany({
where: { userId, eventId },
});
};

/**
* @params id: number
* @params data: EventUserStep
* @returns EventUserStep | null
* @description Updates a user step event with the provided data.
*/
export const updateEventUserStep = async (
id: number,
data: EventUserStep,
): Promise<EventUserStep | null> => {
return await prisma.eventUserStep.update({
where: { id },
data,
});
};

/**
* @params id: number
* @returns EventUserStep | null
* @description Deletes a user step event by its id.
*/
export const deleteEventUserStep = async (
id: number,
): Promise<EventUserStep | null> => {
return await prisma.eventUserStep.delete({ where: { id } });
};

0 comments on commit 5ed9931

Please sign in to comment.