add backend/src/jobs/dailyDunningJob.ts
This commit is contained in:
parent
d6f1bc781a
commit
fa1ed531e3
28
backend/src/jobs/dailyDunningJob.ts
Normal file
28
backend/src/jobs/dailyDunningJob.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import 'dotenv/config';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PaymentService } from '../modules/banking/paymentService';
|
||||
|
||||
/**
|
||||
* Täglicher Cron-Job (z.B. via Supabase Scheduled Edge Function oder
|
||||
* node-cron: `0 8 * * *` = jeden Tag 08:00 Uhr).
|
||||
* Prüft alle überfälligen Zahlungen nach dem 3. Werktag und löst
|
||||
* Mahn-Notifications an Mieter + Vermieter aus.
|
||||
*/
|
||||
export async function runDailyDunningJob() {
|
||||
const prisma = new PrismaClient();
|
||||
const paymentService = new PaymentService(prisma);
|
||||
try {
|
||||
const result = await paymentService.runDailyDunningCheck();
|
||||
console.log(`[dailyDunningJob] ${result.dunningsSent} Mahnungen versendet.`);
|
||||
return result;
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
runDailyDunningJob().catch((err) => {
|
||||
console.error('[dailyDunningJob] Fehlgeschlagen:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user