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
24 changes: 18 additions & 6 deletions backend/src/alerts/expiry-alerts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,9 +19,10 @@ export class ExpiryAlertsService {
@Cron(CronExpression.EVERY_DAY_AT_8AM)
async sendExpiryAlerts(): Promise<void> {
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();
}

Expand All @@ -30,6 +31,17 @@ export class ExpiryAlertsService {
// the assigned user (NotificationsService + MailService `warranty-expiring`).
}

private async checkInsuranceExpiries(): Promise<void> {
// 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<void> {
// Query maintenance records scheduled within the lookahead window and notify
// the responsible user (MAINTENANCE_DUE notification).
Expand Down
Loading