From 51a6deb2b58d1db468a1ce7bc670dfb8c9d7ff72 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Mon, 2 Nov 2026 10:00:07 -0500 Subject: [PATCH] feat(mission-reminder): count chain supervisors as rateable leaders The reminder endpoint/lib now treats a supervisor->subordinate command link as a rateable relationship, so a completed mission prompts feedback even when the co-attendees are at equal rank but linked by the mission chain. --- src/app/api/mission-reminder/route.ts | 4 ++-- src/lib/intelligence/missionReminder.ts | 27 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/app/api/mission-reminder/route.ts b/src/app/api/mission-reminder/route.ts index 4b722c5f..bc0e214c 100644 --- a/src/app/api/mission-reminder/route.ts +++ b/src/app/api/mission-reminder/route.ts @@ -11,8 +11,8 @@ export const runtime = "nodejs"; * GET /api/mission-reminder * * Returns recently completed main operations (within 72h of completion) where the - * authenticated user RSVP'd "yes" and at least one strictly higher-ranked - * co-attendee also RSVP'd "yes". The client uses this to prompt mission + * authenticated user RSVP'd "yes" and at least one rateable co-attendee also + * RSVP'd "yes" (a strictly higher-ranked one, or a chain supervisor). The client uses this to prompt mission * feedback. Leader entries carry identity only, no rater/comment data. */ export async function GET(req: NextRequest) { diff --git a/src/lib/intelligence/missionReminder.ts b/src/lib/intelligence/missionReminder.ts index 9a6f4601..5f5da2d4 100644 --- a/src/lib/intelligence/missionReminder.ts +++ b/src/lib/intelligence/missionReminder.ts @@ -1,5 +1,6 @@ import type { Payload } from "payload"; import { getUserRankIndexes } from "@/lib/evaluations/ranks"; +import { resolveMissionChain } from "@/lib/command-chain"; /** * Mission feedback reminder window: a completed main operation only prompts for @@ -114,8 +115,9 @@ export async function getMissionReminders( ]; const rankIndexes = await getUserRankIndexes(payload, attendeeIds); const userRankIndex = rankIndexes.get(user.id); - if (userRankIndex === undefined) return []; + // Chain command links (per mission) add supervisors at any rank, including + // equal rank. Strict-rank leaders still apply for the spectrum. const eligible: Array<{ mission: (typeof missionsRes.docs)[number]; completedAt: string; @@ -124,12 +126,23 @@ export async function getMissionReminders( for (const { mission, completedAt } of candidates) { const yesUsers = yesByMission.get(mission.id) ?? new Set(); if (!yesUsers.has(user.id)) continue; // the user must have RSVP'd "yes" - const leaders = [...yesUsers].filter((id) => { - if (id === user.id) return false; - const index = rankIndexes.get(id); - return index !== undefined && index > userRankIndex; - }); - if (leaders.length === 0) continue; // at least one higher-ranked co-attendee required + const strictLeaders = + userRankIndex === undefined + ? [] + : [...yesUsers].filter((id) => { + if (id === user.id) return false; + const index = rankIndexes.get(id); + return index !== undefined && index > userRankIndex; + }); + const resolved = await resolveMissionChain(payload, mission.id); + const chainLeaders = + resolved.mode === "legacy" + ? [] + : resolved.links + .filter((l) => l.subordinateId === user.id && yesUsers.has(l.supervisorId)) + .map((l) => l.supervisorId); + const leaders = [...new Set([...strictLeaders, ...chainLeaders])]; + if (leaders.length === 0) continue; // at least one rateable co-attendee required eligible.push({ mission, completedAt, leaderIds: leaders }); }