add trip image
This commit is contained in:
@@ -6,6 +6,7 @@ export const tripRepo = {
|
||||
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" },
|
||||
@@ -17,6 +18,7 @@ export const tripRepo = {
|
||||
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" },
|
||||
@@ -28,6 +30,7 @@ export const tripRepo = {
|
||||
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 } } },
|
||||
},
|
||||
|
||||
@@ -9,8 +9,8 @@ interface CreateTripInput {
|
||||
date: Date;
|
||||
maxParticipants: number;
|
||||
price: number;
|
||||
image?: string;
|
||||
organizerId: string;
|
||||
imageUrls?: string[];
|
||||
}
|
||||
|
||||
export const tripService = {
|
||||
@@ -31,6 +31,12 @@ export const tripService = {
|
||||
},
|
||||
|
||||
async createTrip(input: CreateTripInput) {
|
||||
const images = input.imageUrls?.length
|
||||
? {
|
||||
create: input.imageUrls.map((url, i) => ({ url, order: i })),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return tripRepo.create({
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
@@ -39,8 +45,8 @@ export const tripService = {
|
||||
date: input.date,
|
||||
maxParticipants: input.maxParticipants,
|
||||
price: input.price,
|
||||
image: input.image,
|
||||
organizer: { connect: { id: input.organizerId } },
|
||||
images,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -71,7 +77,6 @@ export const tripService = {
|
||||
|
||||
const participant = await participantRepo.create(tripId, userId);
|
||||
|
||||
// Auto update status if full after join
|
||||
const newCount = await participantRepo.countByTrip(tripId);
|
||||
if (newCount >= trip.maxParticipants) {
|
||||
await tripRepo.updateStatus(tripId, "FULL");
|
||||
@@ -88,7 +93,6 @@ export const tripService = {
|
||||
|
||||
const result = await participantRepo.cancel(tripId, userId);
|
||||
|
||||
// Re-open trip if was full
|
||||
const trip = await tripRepo.findById(tripId);
|
||||
if (trip && trip.status === "FULL") {
|
||||
const count = await participantRepo.countByTrip(tripId);
|
||||
|
||||
Reference in New Issue
Block a user