Compare commits
No commits in common. "35185600b468a22ab5d3a53eebb033b134a47aaf" and "fee337747482b309a1096aa331560571a69ff5ae" have entirely different histories.
35185600b4
...
fee3377474
11 changed files with 100 additions and 45248 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,15 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
# v0.13.3
|
|
||||||
|
|
||||||
The rating system is now generic: evaluations no longer store a "kind", so a rating's direction is derived from the rater and ratee's ranks whenever it is read. The two views a profile shows are unchanged: the anonymous leadership aggregate and the latest command review.
|
|
||||||
|
|
||||||
### Changes
|
|
||||||
|
|
||||||
- **Performance reviews.** A rating is stored once per (rater, ratee, mission) with no stored kind. The anonymous leadership aggregate now includes any rating from someone ranked strictly below the ratee; the command review comes from anyone ranked above it. Direction is derived from current ranks, so a single rating moves between the two views as ranks change.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# v0.13.2
|
# v0.13.2
|
||||||
|
|
||||||
Seniors rating a junior from their profile now see "Rate subordinate" instead of "Rate leadership".
|
Seniors rating a junior from their profile now see "Rate subordinate" instead of "Rate leadership".
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "polaris-task-force",
|
"name": "polaris-task-force",
|
||||||
"version": "0.13.3",
|
"version": "0.13.2",
|
||||||
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
|
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
||||||
|
|
@ -64,11 +64,10 @@ async function findUserByUsername(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit (or re-submit) a performance review for the given profile. The rating
|
* Submit (or re-submit) a leadership evaluation for the given profile. The kind
|
||||||
* is stored generically — no `kind` — and the upward/downward read models are
|
* is derived server-side from the rater/ratee rank relationship and attendance;
|
||||||
* derived at read time from the rater/ratee rank relationship. Eligibility is the
|
* it is never accepted from the client. Eligibility is the permission gate here;
|
||||||
* permission gate here; any logged-in user with a strict rank difference may
|
* any logged-in user with a strict rank difference may evaluate.
|
||||||
* evaluate. The direction is derived server-side and never accepted from the client.
|
|
||||||
*/
|
*/
|
||||||
export async function submitEvaluation(input: {
|
export async function submitEvaluation(input: {
|
||||||
username: string;
|
username: string;
|
||||||
|
|
@ -93,7 +92,7 @@ export async function submitEvaluation(input: {
|
||||||
rateeId: ratee.id,
|
rateeId: ratee.id,
|
||||||
missionId: input.missionId,
|
missionId: input.missionId,
|
||||||
});
|
});
|
||||||
if (!eligibility.eligible) {
|
if (!eligibility.eligible || !eligibility.kind) {
|
||||||
return { success: false, error: eligibility.reason ?? "Not eligible to evaluate." };
|
return { success: false, error: eligibility.reason ?? "Not eligible to evaluate." };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,6 +100,7 @@ export async function submitEvaluation(input: {
|
||||||
raterId: user.id as number,
|
raterId: user.id as number,
|
||||||
rateeId: ratee.id,
|
rateeId: ratee.id,
|
||||||
missionId: input.missionId,
|
missionId: input.missionId,
|
||||||
|
kind: eligibility.kind,
|
||||||
level: input.level,
|
level: input.level,
|
||||||
comment: input.comment,
|
comment: input.comment,
|
||||||
});
|
});
|
||||||
|
|
@ -109,10 +109,10 @@ export async function submitEvaluation(input: {
|
||||||
// must not leak who rated whom.
|
// must not leak who rated whom.
|
||||||
await emitGameEvent(payload, {
|
await emitGameEvent(payload, {
|
||||||
type: EventTypes.EvaluationSubmit,
|
type: EventTypes.EvaluationSubmit,
|
||||||
message: "A performance review was submitted.",
|
message: "A leadership evaluation was submitted.",
|
||||||
targetCollection: "evaluations",
|
targetCollection: "evaluations",
|
||||||
targetId: evaluation.id,
|
targetId: evaluation.id,
|
||||||
data: { direction: eligibility.direction },
|
data: { kind: eligibility.kind },
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, data: { created } };
|
return { success: true, data: { created } };
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,18 @@ import { requirePermission } from "@/utils/access-control/hasPermission";
|
||||||
import { PERFORMANCE_LEVELS } from "@/lib/evaluations/levels";
|
import { PERFORMANCE_LEVELS } from "@/lib/evaluations/levels";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performance reviews (a.k.a. leadership evaluations).
|
* Leadership evaluations.
|
||||||
*
|
*
|
||||||
* One row per (rater, ratee, mission) — the uniqueness is enforced by the
|
* One row per (rater, ratee, mission, kind) — the uniqueness is enforced by the
|
||||||
* service layer (`upsertEvaluation` in `src/lib/evaluations`), not by a DB
|
* service layer (`upsertEvaluation` in `src/lib/evaluations`), not by a DB
|
||||||
* constraint. There is no stored "kind": the upward/downward split is derived
|
* constraint.
|
||||||
* at read time from the rater/ratee rank relationship (see `getLeaderAggregate`
|
|
||||||
* and `getLatestSubordinateLevel`).
|
|
||||||
*
|
*
|
||||||
* Eligibility (rank-based, see `evaluateEligibility` in `src/lib/evaluations`):
|
* Eligibility (rank-based, see `evaluateEligibility` in `src/lib/evaluations`):
|
||||||
* a strict rank gap between rater and ratee plus a yes-RSVP from at least one
|
* a strict rank gap between rater and ratee plus a yes-RSVP from at least one
|
||||||
* of them on the mission. An upward rating (junior rates senior) feeds the
|
* of them on the mission. Upward ratings (junior rates senior) are stored as
|
||||||
* anonymous leadership aggregate; a downward rating (senior rates junior) is a
|
* `leader-direct`; downward ratings (senior rates junior) as `subordinate`.
|
||||||
* command review.
|
* `leader-indirect` only exists on legacy rows written while eligibility was
|
||||||
|
* assignment-based.
|
||||||
*
|
*
|
||||||
* Privacy model: raw documents are only readable/writable by users holding the
|
* Privacy model: raw documents are only readable/writable by users holding the
|
||||||
* `evaluations:*` permissions (admin/developer via role docs). Normal users never
|
* `evaluations:*` permissions (admin/developer via role docs). Normal users never
|
||||||
|
|
@ -28,7 +27,7 @@ export const Evaluations: CollectionConfig = {
|
||||||
slug: "evaluations",
|
slug: "evaluations",
|
||||||
admin: {
|
admin: {
|
||||||
group: "Users",
|
group: "Users",
|
||||||
defaultColumns: ["ratee", "rater", "mission", "level"],
|
defaultColumns: ["ratee", "rater", "mission", "kind", "level"],
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
read: requirePermission("evaluations:read"),
|
read: requirePermission("evaluations:read"),
|
||||||
|
|
@ -59,6 +58,25 @@ export const Evaluations: CollectionConfig = {
|
||||||
relationTo: "missions",
|
relationTo: "missions",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "kind",
|
||||||
|
type: "select",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "Leader (junior rates senior)",
|
||||||
|
value: "leader-direct",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Leader (legacy indirect)",
|
||||||
|
value: "leader-indirect",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Subordinate (senior rates junior)",
|
||||||
|
value: "subordinate",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "level",
|
name: "level",
|
||||||
type: "select",
|
type: "select",
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,27 @@ import {
|
||||||
type PerformanceLevelId,
|
type PerformanceLevelId,
|
||||||
} from "./levels";
|
} from "./levels";
|
||||||
import { missionEndTime } from "@/lib/intelligence/missionLifecycle";
|
import { missionEndTime } from "@/lib/intelligence/missionLifecycle";
|
||||||
import { getUserRankIndexes, rankDirection, type RankDirection } from "./ranks";
|
import { rankDirection } from "./ranks";
|
||||||
|
|
||||||
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
|
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shape of an evaluations doc as consumed by this service (depth 0). There is no
|
* The evaluation kinds. Since the rank-based rework only two kinds are ever
|
||||||
* `kind` field: the upward/downward split is derived from ranks at read time, so
|
* written: `leader-direct` for an upward rating (junior rates senior, feeds
|
||||||
* the same stored row is bucketed differently as ranks change.
|
* the leader aggregate) and `subordinate` for a downward rating (senior rates
|
||||||
|
* junior). `leader-indirect` is legacy: rows written while eligibility was
|
||||||
|
* assignment-based keep it so their aggregates stay intact, but nothing new
|
||||||
|
* produces it.
|
||||||
*/
|
*/
|
||||||
|
export type EvaluationKind = "leader-direct" | "leader-indirect" | "subordinate";
|
||||||
|
|
||||||
|
/** Shape of an evaluations doc as consumed by this service (depth 0). */
|
||||||
export interface EvaluationDoc {
|
export interface EvaluationDoc {
|
||||||
id: number;
|
id: number;
|
||||||
rater: number;
|
rater: number;
|
||||||
ratee: number;
|
ratee: number;
|
||||||
mission: number;
|
mission: number;
|
||||||
|
kind: EvaluationKind;
|
||||||
level: PerformanceLevelId;
|
level: PerformanceLevelId;
|
||||||
comment: string | null;
|
comment: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
|
@ -86,7 +93,7 @@ export async function hasYesAttendance(
|
||||||
|
|
||||||
export interface EligibilityResult {
|
export interface EligibilityResult {
|
||||||
eligible: boolean;
|
eligible: boolean;
|
||||||
direction?: RankDirection;
|
kind?: EvaluationKind;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,21 +159,22 @@ export async function evaluateEligibility(
|
||||||
return { eligible: false, reason: "No attendance recorded for this mission." };
|
return { eligible: false, reason: "No attendance recorded for this mission." };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { eligible: true, direction };
|
return { eligible: true, kind: direction === "upward" ? "leader-direct" : "subordinate" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpsertEvaluationInput {
|
export interface UpsertEvaluationInput {
|
||||||
raterId: number;
|
raterId: number;
|
||||||
rateeId: number;
|
rateeId: number;
|
||||||
missionId: number;
|
missionId: number;
|
||||||
|
kind: EvaluationKind;
|
||||||
level: PerformanceLevelId;
|
level: PerformanceLevelId;
|
||||||
comment?: string;
|
comment?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One row per (rater, ratee, mission). An existing evaluation for that tuple
|
* One row per (rater, ratee, mission, kind). An existing evaluation for that tuple
|
||||||
* is updated in place; otherwise a new one is created. Enforced here in the
|
* is updated in place; otherwise a new one is created. Enforced here in the service
|
||||||
* service layer — there is deliberately no DB constraint to hand-maintain.
|
* layer — there is deliberately no DB constraint to hand-maintain.
|
||||||
*/
|
*/
|
||||||
export async function upsertEvaluation(
|
export async function upsertEvaluation(
|
||||||
payload: PayloadType,
|
payload: PayloadType,
|
||||||
|
|
@ -183,6 +191,7 @@ export async function upsertEvaluation(
|
||||||
{ rater: { equals: input.raterId } },
|
{ rater: { equals: input.raterId } },
|
||||||
{ ratee: { equals: input.rateeId } },
|
{ ratee: { equals: input.rateeId } },
|
||||||
{ mission: { equals: input.missionId } },
|
{ mission: { equals: input.missionId } },
|
||||||
|
{ kind: { equals: input.kind } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
|
@ -207,6 +216,7 @@ export async function upsertEvaluation(
|
||||||
rater: input.raterId,
|
rater: input.raterId,
|
||||||
ratee: input.rateeId,
|
ratee: input.rateeId,
|
||||||
mission: input.missionId,
|
mission: input.missionId,
|
||||||
|
kind: input.kind,
|
||||||
level: input.level,
|
level: input.level,
|
||||||
comment: input.comment ?? null,
|
comment: input.comment ?? null,
|
||||||
},
|
},
|
||||||
|
|
@ -218,7 +228,7 @@ export async function upsertEvaluation(
|
||||||
|
|
||||||
export interface LeaderEvaluationAggregate {
|
export interface LeaderEvaluationAggregate {
|
||||||
rateeId: number;
|
rateeId: number;
|
||||||
/** Distinct raters across this ratee's upward (junior-rating-senior) evaluations. */
|
/** Distinct raters across all leader-kind evaluations. */
|
||||||
totalRaters: number;
|
totalRaters: number;
|
||||||
/** False while raters are below ANONYMITY_THRESHOLD — breakdown withheld. */
|
/** False while raters are below ANONYMITY_THRESHOLD — breakdown withheld. */
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
|
@ -244,12 +254,11 @@ export interface LeaderMissionAggregate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anonymous aggregate of a ratee's upward evaluations (each from a rater ranked
|
* Anonymous aggregate of leader-kind evaluations (direct + indirect) for a ratee.
|
||||||
* strictly below the ratee) for a ratee. The per-level breakdown and average are
|
* The per-level breakdown and average are only exposed once at least
|
||||||
* only exposed once at least ANONYMITY_THRESHOLD distinct raters have evaluated,
|
* ANONYMITY_THRESHOLD distinct raters have evaluated — below that, `visible` is
|
||||||
* where direction is derived from the current ranks rather than a stored kind.
|
* false and the numbers are null so no rater can be identified. No rater identity
|
||||||
* Below that threshold, `visible` is false and the numbers are null so no rater
|
* or comment ever appears in the output.
|
||||||
* can be identified. No rater identity or comment ever appears in the output.
|
|
||||||
*/
|
*/
|
||||||
export async function getLeaderAggregate(
|
export async function getLeaderAggregate(
|
||||||
payload: PayloadType,
|
payload: PayloadType,
|
||||||
|
|
@ -257,23 +266,24 @@ export async function getLeaderAggregate(
|
||||||
): Promise<LeaderEvaluationAggregate> {
|
): Promise<LeaderEvaluationAggregate> {
|
||||||
const res = await payload.find({
|
const res = await payload.find({
|
||||||
collection: "evaluations",
|
collection: "evaluations",
|
||||||
where: { ratee: { equals: rateeId } },
|
where: {
|
||||||
|
and: [{ ratee: { equals: rateeId } }, { kind: { in: ["leader-direct", "leader-indirect"] } }],
|
||||||
|
},
|
||||||
depth: 0,
|
depth: 0,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
const docs = res.docs as unknown as EvaluationDoc[];
|
const docs = res.docs as unknown as EvaluationDoc[];
|
||||||
const { upward } = await partitionByDirection(payload, rateeId, docs);
|
const totalRaters = new Set(docs.map((d) => d.rater)).size;
|
||||||
const totalRaters = new Set(upward.map((d) => d.rater)).size;
|
|
||||||
|
|
||||||
if (totalRaters < ANONYMITY_THRESHOLD) {
|
if (totalRaters < ANONYMITY_THRESHOLD) {
|
||||||
return { rateeId, totalRaters, visible: false, levels: null, averageScore: null, missions: [] };
|
return { rateeId, totalRaters, visible: false, levels: null, averageScore: null, missions: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const counts = new Map<string, number>();
|
const counts = new Map<string, number>();
|
||||||
for (const d of upward) {
|
for (const d of docs) {
|
||||||
counts.set(d.level, (counts.get(d.level) ?? 0) + 1);
|
counts.set(d.level, (counts.get(d.level) ?? 0) + 1);
|
||||||
}
|
}
|
||||||
const totalDocs = upward.length;
|
const totalDocs = docs.length;
|
||||||
const levels = PERFORMANCE_LEVELS.map((l) => {
|
const levels = PERFORMANCE_LEVELS.map((l) => {
|
||||||
const count = counts.get(l.id) ?? 0;
|
const count = counts.get(l.id) ?? 0;
|
||||||
return {
|
return {
|
||||||
|
|
@ -286,15 +296,15 @@ export async function getLeaderAggregate(
|
||||||
};
|
};
|
||||||
}).filter((l) => l.count > 0);
|
}).filter((l) => l.count > 0);
|
||||||
|
|
||||||
const averageScore = upward.length
|
const averageScore = totalDocs
|
||||||
? Math.round(
|
? Math.round(
|
||||||
(upward.reduce((sum, d) => sum + (getPerformanceLevel(d.level)?.score ?? 0), 0) /
|
(docs.reduce((sum, d) => sum + (getPerformanceLevel(d.level)?.score ?? 0), 0) /
|
||||||
upward.length) *
|
totalDocs) *
|
||||||
100,
|
100,
|
||||||
) / 100
|
) / 100
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const missionIds = [...new Set(upward.map((doc) => doc.mission))];
|
const missionIds = [...new Set(docs.map((doc) => doc.mission))];
|
||||||
const missionRows = await Promise.all(
|
const missionRows = await Promise.all(
|
||||||
missionIds.map(async (missionId) => {
|
missionIds.map(async (missionId) => {
|
||||||
const missionResult = await payload.findByID({
|
const missionResult = await payload.findByID({
|
||||||
|
|
@ -303,7 +313,7 @@ export async function getLeaderAggregate(
|
||||||
depth: 0,
|
depth: 0,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
const missionDocs = upward.filter((doc) => doc.mission === missionId);
|
const missionDocs = docs.filter((doc) => doc.mission === missionId);
|
||||||
const missionRaters = new Set(missionDocs.map((doc) => doc.rater)).size;
|
const missionRaters = new Set(missionDocs.map((doc) => doc.rater)).size;
|
||||||
const missionScore = missionDocs.reduce(
|
const missionScore = missionDocs.reduce(
|
||||||
(sum, doc) => sum + (getPerformanceLevel(doc.level)?.score ?? 0),
|
(sum, doc) => sum + (getPerformanceLevel(doc.level)?.score ?? 0),
|
||||||
|
|
@ -332,40 +342,9 @@ export async function getLeaderAggregate(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a ratee's evaluations into the two read models purely by current rank
|
* The most recent subordinate-kind evaluation for a ratee, reduced to the level
|
||||||
* direction, since the stored `kind` was removed. `upward` ratings (rater
|
* definition plus mission and timestamp. Rater identity and comment are private
|
||||||
* strictly junior to the ratee) feed the anonymous leadership aggregate;
|
* and intentionally absent from this output.
|
||||||
* `downward` ratings (rater strictly senior) are command reviews. Ratings where
|
|
||||||
* the two ranks are equal or unresolvable appear in neither bucket.
|
|
||||||
*/
|
|
||||||
async function partitionByDirection(
|
|
||||||
payload: PayloadType,
|
|
||||||
rateeId: number,
|
|
||||||
docs: EvaluationDoc[],
|
|
||||||
): Promise<{ upward: EvaluationDoc[]; downward: EvaluationDoc[] }> {
|
|
||||||
const raters = docs.map((d) => d.rater);
|
|
||||||
const indexes = await getUserRankIndexes(payload, [rateeId, ...raters]);
|
|
||||||
const rateeIndex = indexes.get(rateeId);
|
|
||||||
if (rateeIndex === undefined) return { upward: [], downward: [] };
|
|
||||||
const upward: EvaluationDoc[] = [];
|
|
||||||
const downward: EvaluationDoc[] = [];
|
|
||||||
for (const doc of docs) {
|
|
||||||
const raterIndex = indexes.get(doc.rater);
|
|
||||||
if (raterIndex === undefined) continue;
|
|
||||||
if (raterIndex < rateeIndex) {
|
|
||||||
upward.push(doc);
|
|
||||||
} else if (raterIndex > rateeIndex) {
|
|
||||||
downward.push(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { upward, downward };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The most recent downward evaluation (a senior rating a junior) for a ratee,
|
|
||||||
* reduced to the level definition plus mission and timestamp. Rater identity and
|
|
||||||
* comment are private and intentionally absent from this output. Direction is
|
|
||||||
* derived from the current ranks, so no `kind` is stored or read.
|
|
||||||
*/
|
*/
|
||||||
export async function getLatestSubordinateLevel(
|
export async function getLatestSubordinateLevel(
|
||||||
payload: PayloadType,
|
payload: PayloadType,
|
||||||
|
|
@ -373,14 +352,15 @@ export async function getLatestSubordinateLevel(
|
||||||
): Promise<{ level: PerformanceLevel; missionId: number; at: string } | null> {
|
): Promise<{ level: PerformanceLevel; missionId: number; at: string } | null> {
|
||||||
const res = await payload.find({
|
const res = await payload.find({
|
||||||
collection: "evaluations",
|
collection: "evaluations",
|
||||||
where: { ratee: { equals: rateeId } },
|
where: {
|
||||||
|
and: [{ ratee: { equals: rateeId } }, { kind: { equals: "subordinate" } }],
|
||||||
|
},
|
||||||
sort: "-updatedAt",
|
sort: "-updatedAt",
|
||||||
|
limit: 1,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
});
|
});
|
||||||
const docs = res.docs as unknown as EvaluationDoc[];
|
const doc = res.docs[0] as unknown as EvaluationDoc | undefined;
|
||||||
const { downward } = await partitionByDirection(payload, rateeId, docs);
|
|
||||||
const doc = downward[0];
|
|
||||||
if (!doc) return null;
|
if (!doc) return null;
|
||||||
const level = getPerformanceLevel(doc.level);
|
const level = getPerformanceLevel(doc.level);
|
||||||
if (!level) return null;
|
if (!level) return null;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,13 +0,0 @@
|
||||||
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
|
||||||
|
|
||||||
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
||||||
await db.execute(sql`
|
|
||||||
ALTER TABLE "evaluations" DROP COLUMN "kind";
|
|
||||||
DROP TYPE "public"."enum_evaluations_kind";`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
||||||
await db.execute(sql`
|
|
||||||
CREATE TYPE "public"."enum_evaluations_kind" AS ENUM('leader-direct', 'leader-indirect', 'subordinate');
|
|
||||||
ALTER TABLE "evaluations" ADD COLUMN "kind" "enum_evaluations_kind" NOT NULL;`)
|
|
||||||
}
|
|
||||||
|
|
@ -151,7 +151,6 @@ import * as migration_20261022_170228_add_vehicle_mod_field from './20261022_170
|
||||||
import * as migration_20261026_073228_add_vehicle_category_static_and_drone from './20261026_073228_add_vehicle_category_static_and_drone';
|
import * as migration_20261026_073228_add_vehicle_category_static_and_drone from './20261026_073228_add_vehicle_category_static_and_drone';
|
||||||
import * as migration_20261026_195910_add_vehicle_disallowed_cargo_field from './20261026_195910_add_vehicle_disallowed_cargo_field';
|
import * as migration_20261026_195910_add_vehicle_disallowed_cargo_field from './20261026_195910_add_vehicle_disallowed_cargo_field';
|
||||||
import * as migration_20261026_205453_add_operation_effects_pending_action_and_decisions from './20261026_205453_add_operation_effects_pending_action_and_decisions';
|
import * as migration_20261026_205453_add_operation_effects_pending_action_and_decisions from './20261026_205453_add_operation_effects_pending_action_and_decisions';
|
||||||
import * as migration_20261031_064618_drop_evaluation_kind from './20261031_064618_drop_evaluation_kind';
|
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
{
|
{
|
||||||
|
|
@ -917,11 +916,6 @@ export const migrations = [
|
||||||
{
|
{
|
||||||
up: migration_20261026_205453_add_operation_effects_pending_action_and_decisions.up,
|
up: migration_20261026_205453_add_operation_effects_pending_action_and_decisions.up,
|
||||||
down: migration_20261026_205453_add_operation_effects_pending_action_and_decisions.down,
|
down: migration_20261026_205453_add_operation_effects_pending_action_and_decisions.down,
|
||||||
name: '20261026_205453_add_operation_effects_pending_action_and_decisions',
|
name: '20261026_205453_add_operation_effects_pending_action_and_decisions'
|
||||||
},
|
|
||||||
{
|
|
||||||
up: migration_20261031_064618_drop_evaluation_kind.up,
|
|
||||||
down: migration_20261031_064618_drop_evaluation_kind.down,
|
|
||||||
name: '20261031_064618_drop_evaluation_kind'
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4710,6 +4710,7 @@ export interface Evaluation {
|
||||||
rater: number | User;
|
rater: number | User;
|
||||||
ratee: number | User;
|
ratee: number | User;
|
||||||
mission: number | Mission;
|
mission: number | Mission;
|
||||||
|
kind: 'leader-direct' | 'leader-indirect' | 'subordinate';
|
||||||
level: 'exceptional' | 'excellent' | 'proficient' | 'adequate' | 'moderate' | 'under-review';
|
level: 'exceptional' | 'excellent' | 'proficient' | 'adequate' | 'moderate' | 'under-review';
|
||||||
/**
|
/**
|
||||||
* Private free-text note. Never shown to normal users; managers only.
|
* Private free-text note. Never shown to normal users; managers only.
|
||||||
|
|
@ -10414,6 +10415,7 @@ export interface EvaluationsSelect<T extends boolean = true> {
|
||||||
rater?: T;
|
rater?: T;
|
||||||
ratee?: T;
|
ratee?: T;
|
||||||
mission?: T;
|
mission?: T;
|
||||||
|
kind?: T;
|
||||||
level?: T;
|
level?: T;
|
||||||
comment?: T;
|
comment?: T;
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
|
|
|
||||||
|
|
@ -296,21 +296,21 @@ describe("Leadership evaluations", () => {
|
||||||
expect(isMissionEvaluable("Active", justStarted, 240)).toBe(false);
|
expect(isMissionEvaluable("Active", justStarted, 240)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("derives the evaluation direction from rank relation and shared attendance", async () => {
|
it("derives the evaluation kind from rank relation and shared attendance", async () => {
|
||||||
const cases = [
|
const cases = [
|
||||||
// Junior rates a senior (rater attended) -> upward leader rating.
|
// Junior rates a senior (rater attended) -> upward leader rating.
|
||||||
{ input: { raterId: subordinateB.id, rateeId: leaderA.id }, expectDirection: "upward" },
|
{ input: { raterId: subordinateB.id, rateeId: leaderA.id }, expectKind: "leader-direct" },
|
||||||
// Mid rates the senior (rater attended) -> also upward, no assignment needed.
|
// Mid rates the senior (rater attended) -> also upward, no assignment needed.
|
||||||
{ input: { raterId: participantC.id, rateeId: leaderA.id }, expectDirection: "upward" },
|
{ input: { raterId: participantC.id, rateeId: leaderA.id }, expectKind: "leader-direct" },
|
||||||
// Senior rates a junior -> downward subordinate rating.
|
// Senior rates a junior -> downward subordinate rating.
|
||||||
{ input: { raterId: leaderA.id, rateeId: subordinateB.id }, expectDirection: "downward" },
|
{ input: { raterId: leaderA.id, rateeId: subordinateB.id }, expectKind: "subordinate" },
|
||||||
// F never RSVPed, but E did: one side attending anchors the mission.
|
// F never RSVPed, but E did: one side attending anchors the mission.
|
||||||
{ input: { raterId: noRsvpF.id, rateeId: participantE.id }, expectDirection: "upward" },
|
{ input: { raterId: noRsvpF.id, rateeId: participantE.id }, expectKind: "leader-direct" },
|
||||||
];
|
];
|
||||||
for (const { input, expectDirection } of cases) {
|
for (const { input, expectKind } of cases) {
|
||||||
const result = await evaluateEligibility(payload, { ...input, missionId: missionCompletedId });
|
const result = await evaluateEligibility(payload, { ...input, missionId: missionCompletedId });
|
||||||
expect(result.eligible).toBe(true);
|
expect(result.eligible).toBe(true);
|
||||||
expect(result.direction).toBe(expectDirection);
|
expect(result.kind).toBe(expectKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal ranks can never rate each other, even with both on the roster.
|
// Equal ranks can never rate each other, even with both on the roster.
|
||||||
|
|
@ -357,11 +357,12 @@ describe("Leadership evaluations", () => {
|
||||||
expect(tooEarly.eligible).toBe(false);
|
expect(tooEarly.eligible).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps one row per rater/ratee/mission", async () => {
|
it("keeps one row per rater/ratee/mission/kind", async () => {
|
||||||
const first = await upsertEvaluation(payload, {
|
const first = await upsertEvaluation(payload, {
|
||||||
raterId: subordinateB.id,
|
raterId: subordinateB.id,
|
||||||
rateeId: leaderA.id,
|
rateeId: leaderA.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "leader-direct",
|
||||||
level: "excellent",
|
level: "excellent",
|
||||||
comment: "First pass",
|
comment: "First pass",
|
||||||
});
|
});
|
||||||
|
|
@ -372,6 +373,7 @@ describe("Leadership evaluations", () => {
|
||||||
raterId: subordinateB.id,
|
raterId: subordinateB.id,
|
||||||
rateeId: leaderA.id,
|
rateeId: leaderA.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "leader-direct",
|
||||||
level: "proficient",
|
level: "proficient",
|
||||||
comment: "Revised",
|
comment: "Revised",
|
||||||
});
|
});
|
||||||
|
|
@ -386,6 +388,7 @@ describe("Leadership evaluations", () => {
|
||||||
{ rater: { equals: subordinateB.id } },
|
{ rater: { equals: subordinateB.id } },
|
||||||
{ ratee: { equals: leaderA.id } },
|
{ ratee: { equals: leaderA.id } },
|
||||||
{ mission: { equals: missionCompletedId } },
|
{ mission: { equals: missionCompletedId } },
|
||||||
|
{ kind: { equals: "leader-direct" } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
|
@ -400,6 +403,7 @@ describe("Leadership evaluations", () => {
|
||||||
raterId: participantC.id,
|
raterId: participantC.id,
|
||||||
rateeId: leaderA.id,
|
rateeId: leaderA.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "leader-indirect",
|
||||||
level: "excellent",
|
level: "excellent",
|
||||||
});
|
});
|
||||||
evaluationIds.push(c.evaluation.id);
|
evaluationIds.push(c.evaluation.id);
|
||||||
|
|
@ -417,6 +421,7 @@ describe("Leadership evaluations", () => {
|
||||||
raterId: participantE.id,
|
raterId: participantE.id,
|
||||||
rateeId: leaderA.id,
|
rateeId: leaderA.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "leader-indirect",
|
||||||
level: "exceptional",
|
level: "exceptional",
|
||||||
});
|
});
|
||||||
evaluationIds.push(e.evaluation.id);
|
evaluationIds.push(e.evaluation.id);
|
||||||
|
|
@ -443,6 +448,7 @@ describe("Leadership evaluations", () => {
|
||||||
raterId: leaderA.id,
|
raterId: leaderA.id,
|
||||||
rateeId: subordinateB.id,
|
rateeId: subordinateB.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "subordinate",
|
||||||
level: "adequate",
|
level: "adequate",
|
||||||
comment: "Manager note — must never leak",
|
comment: "Manager note — must never leak",
|
||||||
});
|
});
|
||||||
|
|
@ -451,6 +457,7 @@ describe("Leadership evaluations", () => {
|
||||||
raterId: leaderA.id,
|
raterId: leaderA.id,
|
||||||
rateeId: subordinateB.id,
|
rateeId: subordinateB.id,
|
||||||
missionId: missionCompletedId,
|
missionId: missionCompletedId,
|
||||||
|
kind: "subordinate",
|
||||||
level: "excellent",
|
level: "excellent",
|
||||||
});
|
});
|
||||||
evaluationIds.push(revised.evaluation.id);
|
evaluationIds.push(revised.evaluation.id);
|
||||||
|
|
@ -532,7 +539,7 @@ describe("Leadership evaluations", () => {
|
||||||
expect(typeof doc.rater).toBe("number");
|
expect(typeof doc.rater).toBe("number");
|
||||||
expect(typeof doc.ratee).toBe("number");
|
expect(typeof doc.ratee).toBe("number");
|
||||||
expect(typeof doc.mission).toBe("number");
|
expect(typeof doc.mission).toBe("number");
|
||||||
expect(typeof doc.level).toBe("string");
|
expect(["leader-direct", "leader-indirect", "subordinate"]).toContain(doc.kind);
|
||||||
} finally {
|
} finally {
|
||||||
await payload.delete({ collection: "roles", id: role.id, overrideAccess: true }).catch(() => {});
|
await payload.delete({ collection: "roles", id: role.id, overrideAccess: true }).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ async function makeMission(label: string, authorId: number): Promise<number> {
|
||||||
async function makeEvaluation(missionId: number, ratee: number): Promise<number> {
|
async function makeEvaluation(missionId: number, ratee: number): Promise<number> {
|
||||||
const doc = await payload.create({
|
const doc = await payload.create({
|
||||||
collection: "evaluations",
|
collection: "evaluations",
|
||||||
data: { rater: raterId, ratee, mission: missionId, level: "proficient" },
|
data: { rater: raterId, ratee, mission: missionId, kind: "leader-direct", level: "proficient" },
|
||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue