1
0
Fork 0

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.
This commit is contained in:
Jason Fraley 2026-11-02 10:00:07 -05:00
parent 79f790e02b
commit 51a6deb2b5
2 changed files with 22 additions and 9 deletions

View file

@ -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) {

View file

@ -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<number>();
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 });
}