Skip to content

Commit

Permalink
refactor: findLatestPayment in payment service
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-milad committed Aug 22, 2024
1 parent ef5bc46 commit a4cbbf9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export class PaymentService {
constructor(
private prisma: PrismaService,
private walletService: WalletService,
) {}
) { }

async createPayment(): Promise<Payment> {
const latestPayment = await this.prisma.payment.findFirst({
orderBy: {
createdAt: "desc",
},
});
const latestPayment = await this.findLatestPayment();

if (latestPayment) {
const incrementedWalletAccount = latestPayment.walletAccount + 1;
const incrementedWalletIndex = latestPayment.walletIndex + 1;
Expand All @@ -34,6 +32,13 @@ export class PaymentService {
},
});
}
async findLatestPayment(): Promise<Payment | null> {
return await this.prisma.payment.findFirst({
orderBy: {
createdAt: "desc",
},
});
}
async findInitPayment(): Promise<Payment[]> {
return await this.prisma.payment.findMany({ where: { paymentStatus: "INIT" } });
}
Expand Down

0 comments on commit a4cbbf9

Please sign in to comment.