Files
setrip/server/repositories/payment.repo.ts
T
2026-05-08 20:59:01 +07:00

43 lines
1019 B
TypeScript

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 });
},
};