Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/payments/services/payment-enrollment-validator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Payment } from '../entities/payment.entity';

@Injectable()
export class PaymentEnrollmentValidatorService {
constructor(
@InjectRepository(Payment)
private readonly paymentRepo: Repository<Payment>,
) {}

async validateEnrollmentExists(enrollmentId: string): Promise<boolean> {
if (!enrollmentId) return true;
const result = await this.paymentRepo.query('SELECT id FROM enrollments WHERE id = $1', [
enrollmentId,
]);
return result.length > 0;
}

async findOrphanedPayments(): Promise<Payment[]> {
return this.paymentRepo.query(
'SELECT p.* FROM payments p LEFT JOIN enrollments e ON e.id = p."enrollmentId" WHERE p."enrollmentId" IS NOT NULL AND e.id IS NULL',
);
}
}
Loading