From 8ef26ae039bc19c0cb29f0270868f31fb5e6b142 Mon Sep 17 00:00:00 2001 From: demilade-git <230550802+demilade18-git@users.noreply.github.com> Date: Fri, 25 Sep 2026 13:36:32 +0100 Subject: [PATCH] Wire insurance expiry checks into the daily alert run ExpiryAlertsService only checked warranty and maintenance expiries, not insurance. Adds checkInsuranceExpiries(), called from the same daily cron run as the existing checks. Asset currently has no insuranceExpiry field (only warrantyExpiry), so this is a stub matching the existing checkWarrantyExpiries/ checkMaintenanceDue maturity level rather than a real query - flagged in a comment so the gap is visible once the field is added. --- backend/src/alerts/expiry-alerts.service.ts | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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).