diff --git a/backend/src/alerts/expiry-alerts.service.ts b/backend/src/alerts/expiry-alerts.service.ts index 0869e101..3122c20b 100644 --- a/backend/src/alerts/expiry-alerts.service.ts +++ b/backend/src/alerts/expiry-alerts.service.ts @@ -2,12 +2,12 @@ import { Injectable, Logger } from '@nestjs/common'; import { Cron, CronExpression } from '@nestjs/schedule'; /** - * Sends daily alerts for warranties and scheduled maintenance that are due to - * expire soon, so nothing lapses unnoticed. + * Sends daily alerts for warranties, insurance, and scheduled maintenance + * that are due to expire soon, so nothing lapses unnoticed. * - * Runs once a day; finds assets whose warranty (or next maintenance) falls - * within the lookahead window and creates a notification for the responsible - * user. + * Runs once a day; finds assets whose warranty/insurance (or next + * maintenance) falls within the lookahead window and creates a + * notification for the responsible user. */ @Injectable() export class ExpiryAlertsService { @@ -19,9 +19,10 @@ export class ExpiryAlertsService { @Cron(CronExpression.EVERY_DAY_AT_8AM) async sendExpiryAlerts(): Promise { this.logger.log( - `Checking for warranties/maintenance expiring within ${this.lookaheadDays} days`, + `Checking for warranties/insurance/maintenance expiring within ${this.lookaheadDays} days`, ); await this.checkWarrantyExpiries(); + await this.checkInsuranceExpiries(); await this.checkMaintenanceDue(); } @@ -30,6 +31,17 @@ export class ExpiryAlertsService { // the assigned user (NotificationsService + MailService `warranty-expiring`). } + private async checkInsuranceExpiries(): Promise { + // Query assets with insuranceExpiry within the lookahead window and notify + // the assigned user (NotificationsService + MailService `insurance-expiring`). + // + // Blocked on data: Asset (assets/entities/asset.entity.ts) currently has + // no `insuranceExpiry` field — only `warrantyExpiry`. That field needs + // to be added (with a migration) before this can query real data; this + // stub is wired into the daily run now so the coverage gap doesn't + // silently reappear once the field exists. + } + private async checkMaintenanceDue(): Promise { // Query maintenance records scheduled within the lookahead window and notify // the responsible user (MAINTENANCE_DUE notification).