Skip to content
Closed
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/collaboration/services/ws-drain.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class WsDrainService {
private draining = false;
private readonly drainPeriodMs = 30000;

startDrain(): void {
this.draining = true;
setTimeout(() => {
this.draining = false;
}, this.drainPeriodMs);
}

isDraining(): boolean {
return this.draining;
}

canAcceptConnection(): boolean {
return !this.draining;
}
}
24 changes: 24 additions & 0 deletions src/payments/services/payment-enrollment-validator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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',
);
}
}