49 lines
1.4 KiB
TypeScript
49 lines
1.4 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 } },
|
|
images: { orderBy: { order: "asc" }, take: 1 },
|
|
_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 } },
|
|
images: { orderBy: { order: "asc" }, take: 1 },
|
|
_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 } },
|
|
images: { orderBy: { order: "asc" } },
|
|
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 } });
|
|
},
|
|
};
|