add booking and payment schema
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
|
||||
export const bookingRepo = {
|
||||
async findById(id: string) {
|
||||
return prisma.booking.findUnique({ where: { id } });
|
||||
},
|
||||
|
||||
async findByParticipantId(participantId: string) {
|
||||
return prisma.booking.findUnique({
|
||||
where: { participantId },
|
||||
include: { payments: { orderBy: { createdAt: "desc" } } },
|
||||
});
|
||||
},
|
||||
|
||||
async findByTripAndUser(tripId: string, userId: string) {
|
||||
return prisma.booking.findFirst({
|
||||
where: { tripId, userId },
|
||||
include: { payments: { orderBy: { createdAt: "desc" } } },
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Daftar booking di trip ini yang masih menunggu konfirmasi pembayaran
|
||||
* dari organizer (Payment MANUAL status AWAITING).
|
||||
*/
|
||||
async findAwaitingManualConfirmation(tripId: string) {
|
||||
return prisma.booking.findMany({
|
||||
where: {
|
||||
tripId,
|
||||
status: "AWAITING_PAY",
|
||||
payments: {
|
||||
some: { provider: "MANUAL", status: "AWAITING" },
|
||||
},
|
||||
},
|
||||
include: {
|
||||
participant: true,
|
||||
user: { select: { id: true, name: true, image: true } },
|
||||
payments: {
|
||||
where: { provider: "MANUAL", status: "AWAITING" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
orderBy: { updatedAt: "asc" },
|
||||
});
|
||||
},
|
||||
|
||||
async create(
|
||||
data: Pick<
|
||||
Prisma.BookingUncheckedCreateInput,
|
||||
"tripId" | "userId" | "participantId" | "amount" | "status"
|
||||
>
|
||||
) {
|
||||
return prisma.booking.create({ data });
|
||||
},
|
||||
|
||||
async updateStatus(id: string, status: Prisma.BookingUpdateInput["status"]) {
|
||||
return prisma.booking.update({
|
||||
where: { id },
|
||||
data: { status },
|
||||
});
|
||||
},
|
||||
|
||||
async updateStatusByParticipantId(
|
||||
participantId: string,
|
||||
status: Prisma.BookingUpdateInput["status"]
|
||||
) {
|
||||
return prisma.booking.updateMany({
|
||||
where: { participantId },
|
||||
data: { status },
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
|
||||
export const paymentRepo = {
|
||||
async findById(id: string) {
|
||||
return prisma.payment.findUnique({ where: { id } });
|
||||
},
|
||||
|
||||
async findByExternalOrderId(externalOrderId: string) {
|
||||
return prisma.payment.findUnique({ where: { externalOrderId } });
|
||||
},
|
||||
|
||||
async findActiveManualForBooking(bookingId: string) {
|
||||
return prisma.payment.findFirst({
|
||||
where: {
|
||||
bookingId,
|
||||
provider: "MANUAL",
|
||||
status: { in: ["PENDING", "AWAITING"] },
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
},
|
||||
|
||||
async create(
|
||||
data: Pick<
|
||||
Prisma.PaymentUncheckedCreateInput,
|
||||
| "bookingId"
|
||||
| "provider"
|
||||
| "externalOrderId"
|
||||
| "amount"
|
||||
| "status"
|
||||
| "method"
|
||||
| "expiresAt"
|
||||
>
|
||||
) {
|
||||
return prisma.payment.create({ data });
|
||||
},
|
||||
|
||||
async update(id: string, data: Prisma.PaymentUpdateInput) {
|
||||
return prisma.payment.update({ where: { id }, data });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user