29 lines
751 B
TypeScript
29 lines
751 B
TypeScript
import { prisma } from "@/lib/prisma";
|
|
|
|
export const participantRepo = {
|
|
async findByTripAndUser(tripId: string, userId: string) {
|
|
return prisma.tripParticipant.findUnique({
|
|
where: { tripId_userId: { tripId, userId } },
|
|
});
|
|
},
|
|
|
|
async create(tripId: string, userId: string) {
|
|
return prisma.tripParticipant.create({
|
|
data: { tripId, userId, status: "CONFIRMED" },
|
|
});
|
|
},
|
|
|
|
async countByTrip(tripId: string) {
|
|
return prisma.tripParticipant.count({
|
|
where: { tripId, status: { not: "CANCELLED" } },
|
|
});
|
|
},
|
|
|
|
async cancel(tripId: string, userId: string) {
|
|
return prisma.tripParticipant.update({
|
|
where: { tripId_userId: { tripId, userId } },
|
|
data: { status: "CANCELLED" },
|
|
});
|
|
},
|
|
};
|