- ✅
- ✅ - ✅ - ✅
This commit is contained in:
@@ -4,13 +4,13 @@ import { prisma } from "@/lib/prisma";
|
||||
import { tripRepo, type TripFilters } from "@/server/repositories/trip.repo";
|
||||
import { participantRepo } from "@/server/repositories/participant.repo";
|
||||
import { bookingRepo } from "@/server/repositories/booking.repo";
|
||||
import { bookingService } from "@/server/services/booking.service";
|
||||
import { refundService } from "@/server/services/refund.service";
|
||||
import { payoutService } from "@/server/services/payout.service";
|
||||
import { payoutRepo } from "@/server/repositories/payout.repo";
|
||||
import { LIMITS } from "@/lib/limits";
|
||||
import { utcStartOfDay, isTripDepartureDayPast } from "@/lib/trip-dates";
|
||||
import { isFreeTrip } from "@/lib/trip-pricing";
|
||||
import type { ItineraryItemInput } from "@/lib/itinerary";
|
||||
|
||||
const SERIAL_TX_ATTEMPTS = 6;
|
||||
|
||||
@@ -30,7 +30,6 @@ interface CreateTripInput {
|
||||
destination: string;
|
||||
location: string;
|
||||
meetingPoint?: string;
|
||||
itinerary?: string;
|
||||
whatsIncluded?: string;
|
||||
whatsExcluded?: string;
|
||||
date: Date;
|
||||
@@ -40,6 +39,7 @@ interface CreateTripInput {
|
||||
vibe?: Vibe;
|
||||
organizerId: string;
|
||||
imageUrls?: string[];
|
||||
itineraryItems?: ItineraryItemInput[];
|
||||
}
|
||||
|
||||
export const tripService = {
|
||||
@@ -75,6 +75,18 @@ export const tripService = {
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const itineraryItems = input.itineraryItems?.length
|
||||
? {
|
||||
create: input.itineraryItems.map((item, i) => ({
|
||||
day: item.day,
|
||||
startTime: item.startTime,
|
||||
endTime: item.endTime ?? null,
|
||||
activity: item.activity.trim(),
|
||||
order: i,
|
||||
})),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const tripData = {
|
||||
category: input.category,
|
||||
title: input.title,
|
||||
@@ -82,7 +94,6 @@ export const tripService = {
|
||||
destination: input.destination,
|
||||
location: input.location,
|
||||
meetingPoint: input.meetingPoint,
|
||||
itinerary: input.itinerary,
|
||||
whatsIncluded: input.whatsIncluded,
|
||||
whatsExcluded: input.whatsExcluded,
|
||||
date: input.date,
|
||||
@@ -92,6 +103,7 @@ export const tripService = {
|
||||
vibe: input.vibe,
|
||||
organizer: { connect: { id: input.organizerId } },
|
||||
images,
|
||||
itineraryItems,
|
||||
} satisfies Prisma.TripCreateInput;
|
||||
|
||||
let lastErr: unknown;
|
||||
@@ -377,30 +389,6 @@ export const tripService = {
|
||||
return { ok: true as const };
|
||||
},
|
||||
|
||||
async markParticipantPayment(tripId: string, userId: string) {
|
||||
const trip = await tripRepo.findById(tripId);
|
||||
if (!trip) {
|
||||
throw new Error("Trip tidak ditemukan");
|
||||
}
|
||||
|
||||
if (isFreeTrip(trip)) {
|
||||
throw new Error(
|
||||
"Trip ini gratis — tidak ada pembayaran yang perlu ditandai"
|
||||
);
|
||||
}
|
||||
|
||||
if (isTripDepartureDayPast(trip.date)) {
|
||||
throw new Error("Trip sudah lewat — pembayaran tidak perlu ditandai");
|
||||
}
|
||||
|
||||
const booking = await bookingRepo.findByTripAndUser(tripId, userId);
|
||||
if (!booking || booking.status === "CANCELLED") {
|
||||
throw new Error("Kamu tidak terdaftar di trip ini");
|
||||
}
|
||||
|
||||
return bookingService.markPaidManual(booking.id, userId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Auto-complete trip yang sudah lewat. Dipakai cron harian.
|
||||
*
|
||||
@@ -415,30 +403,6 @@ export const tripService = {
|
||||
return tripRepo.bulkCompletePastTrips(cutoff);
|
||||
},
|
||||
|
||||
async confirmParticipantPayment(
|
||||
tripId: string,
|
||||
participantId: string,
|
||||
organizerId: string
|
||||
) {
|
||||
const trip = await tripRepo.findById(tripId);
|
||||
if (!trip) {
|
||||
throw new Error("Trip tidak ditemukan");
|
||||
}
|
||||
if (trip.organizerId !== organizerId) {
|
||||
throw new Error("Hanya organizer yang bisa mengonfirmasi pembayaran");
|
||||
}
|
||||
if (isFreeTrip(trip)) {
|
||||
throw new Error("Trip ini gratis — tidak ada pembayaran yang perlu dikonfirmasi");
|
||||
}
|
||||
|
||||
const booking = await bookingRepo.findByParticipantId(participantId);
|
||||
if (!booking || booking.tripId !== tripId) {
|
||||
throw new Error("Booking tidak ditemukan");
|
||||
}
|
||||
|
||||
return bookingService.confirmPaidManual(booking.id, organizerId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Organizer batalkan trip (Trip.status = CLOSED). Atomic dalam satu
|
||||
* serializable transaction:
|
||||
|
||||
Reference in New Issue
Block a user