Skip to content

Diya 🔥 fix(multiple): Fixed Weekly Summary Cron + BS History#2252

Merged
one-community merged 1 commit into
developmentfrom
Diya_Fix_WeeklySummaryCron_BSHistory
Jun 19, 2026
Merged

Diya 🔥 fix(multiple): Fixed Weekly Summary Cron + BS History#2252
one-community merged 1 commit into
developmentfrom
Diya_Fix_WeeklySummaryCron_BSHistory

Conversation

@DiyaWadhwani

Copy link
Copy Markdown
Contributor

Description

Fixes two bugs in the weekly cron job that have been causing the weekly summary email to stop sending since May 3rd, and improves blue square expiry handling to preserve historical records.

Fixes # (Weekly Summary Email not sending - Priority High)

Related PRs:

None

Main changes explained:

  • cron.js — Removed weeklyCompanySummaryEmail() call which was throwing TypeError: userhelper.weeklyCompanySummaryEmail is not a function every Sunday, crashing the entire cron job callback and preventing all subsequent jobs from running including emailWeeklySummariesForAllUsers

  • userHelper.js — Rewrote deleteBlueSquareAfterYear:

    • For active users: expired infringements (older than 1 year) are now moved to oldInfringements before being removed from infringements, preserving a permanent historical record
    • For inactive users: expired infringements are still just deleted (no history needed)
    • Previously the function wiped both infringements and oldInfringements for all users with no isActive filter — expired records were being permanently lost

How to test:

  1. Check out this branch and start the backend locally
  2. Confirm weeklyCompanySummaryEmail no longer appears in the cron file
  3. To test emailWeeklySummariesForAllUsers manually, run:
const mongoose = require('mongoose');
require('dotenv').config();
const userHelperFactory = require('./src/helpers/userHelper');
async function main() {
  await mongoose.connect(process.env.MONGO_URI);
  const userhelper = userHelperFactory();
  await userhelper.emailWeeklySummariesForAllUsers();
  await mongoose.disconnect();
}
main();
  1. Confirm it completes without errors, and the logs show users being processed
  2. To test deleteBlueSquareAfterYear, temporarily add a test infringement dated over a year ago to an active user, run the function manually, and confirm it moves to oldInfringements instead of being deleted

Notes:

  • weeklyCompanySummaryEmail was called outside the if (SUNDAY) block, meaning it crashed the cron every week, not just Sundays
  • oldInfringements may occasionally contain duplicates if the weekly processWeeklySummariesByUserId cron already moved the same infringement — this is cosmetic only and does not affect functionality
  • Emails only send in production (NODE_ENV=production), so local testing is safe

@one-community one-community changed the title Diya fix(multiple): Fixed Weekly Summary Cron + BS History Diya 🔥 fix(multiple): Fixed Weekly Summary Cron + BS History Jun 19, 2026
@one-community one-community merged commit ca5d528 into development Jun 19, 2026
2 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants