56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
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" },
|
|
});
|
|
},
|
|
|
|
async reactivate(tripId: string, userId: string) {
|
|
return prisma.tripParticipant.update({
|
|
where: { tripId_userId: { tripId, userId } },
|
|
data: { status: "CONFIRMED" },
|
|
});
|
|
},
|
|
|
|
/** Partisipasi user beserta trip (untuk profil & riwayat). */
|
|
async findWithTripForProfile(userId: string) {
|
|
return prisma.tripParticipant.findMany({
|
|
where: { userId },
|
|
include: {
|
|
trip: {
|
|
include: {
|
|
organizer: { select: { id: true, name: true } },
|
|
images: { orderBy: { order: "asc" }, take: 1 },
|
|
reviews: {
|
|
where: { userId },
|
|
select: { id: true, rating: true },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
orderBy: { createdAt: "desc" },
|
|
});
|
|
},
|
|
};
|