Diya 🔥 (BSemails): Fixed Blue Square assignment Email Hierarchy#2257
Merged
Conversation
one-community
approved these changes
Jun 21, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Fixes the weekly auto-reply email hierarchy so that the correct contextual follow-up email is sent to users who receive a blue square on Sunday, and resolves a timezone mismatch that was silently preventing all auto-reply emails from firing.
Related PRs (if any):
None
Main changes explained:
helpers/userHelper.jsFixed critical timezone/date mismatch in
weeklyAutoReplyEmailFunction:assignBlueSquareForTimeNotMetruns at midnight LA time (Sunday 12 AM), but stores infringement dates as UTCYYYY-MM-DDstrings. In summer (PDT, UTC-7), midnight LA = 7 AM UTC — still Sunday. However the previous code compared againstmoment().tz('America/Los_Angeles').format('YYYY-MM-DD')(today's date at 4 AM), which is correct, but the infringementdatefield was written usingmoment().utc().format('YYYY-MM-DD')at midnight UTC — which in some edge cases resolves to Saturday's date. ReplacedtodayDatewithassignmentDate = moment().tz(COMPANY_TZ).startOf('week').format('YYYY-MM-DD'), which is always the canonical Sunday date regardless of when in Sunday the 4 AM job runs, and always matches what the assignment job wrote.Fixed variable scope crash: Previous version had
hasTodayBlueSquarecomputed before theforloop, referencinguserwhich didn't exist yet — causing aReferenceErrorthat silently crashed the entire function before processing anyone. Moved it inside the loop.Corrected priority hierarchy in
resolveAutoReplyTemplate:if (metHours) return nullguard at the top to prevent double-emailing users already handled bycompleteHoursAndMissedSummary(priority 1)<1MON_TWO_BLUESQUAREis now checked before<2MON_TWO_BLUESQUAREsincenumMonths < 1is a strict subset ofnumMonths < 2Added
metHours && !hasSummaryguard inweeklyAutoReplyEmailFunctionto skip users already sent a priority-1 email bycompleteHoursAndMissedSummary, preventing double-emails. Fetch fieldsweeklySummaries,weeklySummaryOption, andweeklySummaryNotReqadded to the DB query to support this check.Replaced all hardcoded
'America/Los_Angeles'timezone strings throughout the file with theCOMPANY_TZconstant imported from../constants/company, ensuring timezone logic is managed from a single source of truth.startup/userProfileJobs.jsallUserProfileJobs:0 0 * * 0— Sunday midnight, assigns blue squaressummaryNotSubmittedJobs:0 4 * * 0— Sunday 4 AM, sends auto-reply emails (runs after assignment)dailyUserDeactivateJobs:1 0 * * *— daily 12:01 AM, handles deactivationHow to test:
npm installweeklyAutoReplyEmailFunctionwith atargetUserIdoverride:Verify the correct template fires for each scenario by checking the
[autoReply] <email> → <templateKey>console log:COMPLETED_HOURS_25%_64.9%COMPLETED_HOURS_65%_84.9%MISSED_HOURS_BY_<15%<1MON_ONE_BLUESQUARE<1MON_TWO_BLUESQUARE<2MON_TWO_BLUESQUARE<2MON_THREE_BLUESQUARE4TH_BLUE_SQUARESCHEDULED_TIME_OFF_AND_4TH_BLUE_SQUAREcompleteHoursAndMissedSummary, no auto-reply emailConfirm no user receives more than one auto-reply email in a single run.
Confirm users who met their hours and missed their summary only receive the
completeHoursAndMissedSummaryemail, not an additional auto-reply.Note:
startOf('week')in LA time) is semantically more correct regardless — we're always looking for "this week's assignment run" blue square, not "today's" blue square.COMPANY_TZis confirmed to be'America/Los_Angeles'inconstants/company.js. All timezone references now use this constant.inCompleteHoursEmailFunction,weeklyBlueSquareReminderFunction) remain commented out inuserHelper.jsfor reference during the transition period and can be removed in a follow-up cleanup PR onceweeklyAutoReplyEmailFunctionis confirmed stable in production.