Files
setrip/server/repositories/trip.repo.ts
T
2026-04-16 14:51:54 +07:00

46 lines
1.2 KiB
TypeScript

import { prisma } from "@/lib/prisma";
import { Prisma } from "@/app/generated/prisma/client";
export const tripRepo = {
async findAll() {
return prisma.trip.findMany({
include: {
organizer: { select: { id: true, name: true, image: true } },
_count: { select: { participants: true } },
},
orderBy: { date: "asc" },
});
},
async findOpen() {
return prisma.trip.findMany({
where: { status: "OPEN", date: { gte: new Date() } },
include: {
organizer: { select: { id: true, name: true, image: true } },
_count: { select: { participants: true } },
},
orderBy: { date: "asc" },
});
},
async findById(id: string) {
return prisma.trip.findUnique({
where: { id },
include: {
organizer: { select: { id: true, name: true, email: true, image: true } },
participants: {
include: { user: { select: { id: true, name: true, image: true } } },
},
},
});
},
async create(data: Prisma.TripCreateInput) {
return prisma.trip.create({ data });
},
async updateStatus(id: string, status: "OPEN" | "FULL" | "CLOSED" | "COMPLETED") {
return prisma.trip.update({ where: { id }, data: { status } });
},
};