Co-authored-by: Pallav <90088723+Pallava-Joshi@users.noreply.github.com> Co-authored-by: Ryukemeister <sahalrajiv6900@gmail.com> Co-authored-by: Rajiv Sahal <sahalrajiv-extc@atharvacoe.ac.in> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type { PrismaClient } from "@calcom/prisma";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import type {
|
|
IBookingPaymentRepository,
|
|
BookingPaymentWithCredentials,
|
|
CreatePaymentData,
|
|
PaymentForAwaitingEmail,
|
|
} from "./BookingPaymentRepository.interface";
|
|
|
|
export class PrismaBookingPaymentRepository implements IBookingPaymentRepository {
|
|
constructor(private readonly prismaClient: PrismaClient = prisma) {}
|
|
|
|
async findByExternalIdIncludeBookingUserCredentials(
|
|
externalId: string,
|
|
credentialType: string
|
|
): Promise<BookingPaymentWithCredentials | null> {
|
|
return await this.prismaClient.payment.findFirst({
|
|
where: {
|
|
externalId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
amount: true,
|
|
success: true,
|
|
bookingId: true,
|
|
booking: {
|
|
select: {
|
|
user: {
|
|
select: {
|
|
credentials: {
|
|
where: { type: credentialType },
|
|
select: { key: true },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
async createPaymentRecord(data: CreatePaymentData) {
|
|
const createdPayment = await this.prismaClient.payment.create({
|
|
data,
|
|
});
|
|
return createdPayment;
|
|
}
|
|
|
|
async findByIdForAwaitingPaymentEmail(id: number): Promise<PaymentForAwaitingEmail | null> {
|
|
return await this.prismaClient.payment.findUnique({
|
|
where: { id },
|
|
select: {
|
|
success: true,
|
|
externalId: true,
|
|
uid: true,
|
|
paymentOption: true,
|
|
amount: true,
|
|
currency: true,
|
|
app: {
|
|
select: {
|
|
slug: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|