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:
parent
79f790e02b
commit
51a6deb2b5
2 changed files with 22 additions and 9 deletions
|
|
@ -11,8 +11,8 @@ export const runtime = "nodejs";
|
||||||
* GET /api/mission-reminder
|
* GET /api/mission-reminder
|
||||||
*
|
*
|
||||||
* Returns recently completed main operations (within 72h of completion) where the
|
* Returns recently completed main operations (within 72h of completion) where the
|
||||||
* authenticated user RSVP'd "yes" and at least one strictly higher-ranked
|
* authenticated user RSVP'd "yes" and at least one rateable co-attendee also
|
||||||
* co-attendee also RSVP'd "yes". The client uses this to prompt mission
|
* 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.
|
* feedback. Leader entries carry identity only, no rater/comment data.
|
||||||
*/
|
*/
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import type { Payload } from "payload";
|
import type { Payload } from "payload";
|
||||||
import { getUserRankIndexes } from "@/lib/evaluations/ranks";
|
import { getUserRankIndexes } from "@/lib/evaluations/ranks";
|
||||||
|
import { resolveMissionChain } from "@/lib/command-chain";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mission feedback reminder window: a completed main operation only prompts for
|
* 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 rankIndexes = await getUserRankIndexes(payload, attendeeIds);
|
||||||
const userRankIndex = rankIndexes.get(user.id);
|
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<{
|
const eligible: Array<{
|
||||||
mission: (typeof missionsRes.docs)[number];
|
mission: (typeof missionsRes.docs)[number];
|
||||||
completedAt: string;
|
completedAt: string;
|
||||||
|
|
@ -124,12 +126,23 @@ export async function getMissionReminders(
|
||||||
for (const { mission, completedAt } of candidates) {
|
for (const { mission, completedAt } of candidates) {
|
||||||
const yesUsers = yesByMission.get(mission.id) ?? new Set<number>();
|
const yesUsers = yesByMission.get(mission.id) ?? new Set<number>();
|
||||||
if (!yesUsers.has(user.id)) continue; // the user must have RSVP'd "yes"
|
if (!yesUsers.has(user.id)) continue; // the user must have RSVP'd "yes"
|
||||||
const leaders = [...yesUsers].filter((id) => {
|
const strictLeaders =
|
||||||
if (id === user.id) return false;
|
userRankIndex === undefined
|
||||||
const index = rankIndexes.get(id);
|
? []
|
||||||
return index !== undefined && index > userRankIndex;
|
: [...yesUsers].filter((id) => {
|
||||||
});
|
if (id === user.id) return false;
|
||||||
if (leaders.length === 0) continue; // at least one higher-ranked co-attendee required
|
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 });
|
eligible.push({ mission, completedAt, leaderIds: leaders });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue