Files
lincodex/frontend/src/entities/match/model/card-presentation.ts
T

109 lines
3.7 KiB
TypeScript

import type {
AnonymousCardContent,
EvidenceSkillCode,
OrganizationEvidence,
} from "../../../shared/api/schemas";
import type { TrustLevelValue } from "../../../shared/ui";
import {
confirmationLabel,
experienceBandLabels,
gradeLabels,
salaryCompatibilityLabels,
specializationLabels,
stackLabels,
workFormatLabels,
} from "./labels";
export type CardDetails = {
categories: readonly { specialization: string; grade: string; strength: string }[] | null;
selfAssessments:
| readonly {
specialization: string;
declaredGrade: string | null;
confirmed: boolean;
}[]
| null;
stack: readonly string[] | null;
experience: string | null;
workFormats: readonly string[] | null;
salaryCompatibility: string | null;
/** Published projects in the candidate's order; null when the card has none to show. */
projects:
| readonly {
title: string;
description: string | null;
stack: readonly string[];
repositoryVerified: boolean;
}[]
| null;
};
/**
* Maps the full anonymous card to display strings. A null value stays null:
* the contract does not say whether the candidate withheld it or has none,
* and the screen does not guess.
*/
export function presentCard(card: AnonymousCardContent): CardDetails {
return {
categories:
card.categories?.map((category) => ({
specialization: specializationLabels[category.specialization],
grade: gradeLabels[category.grade],
strength: confirmationLabel(category.strength),
})) ?? null,
selfAssessments:
card.self_assessment?.map((item) => ({
specialization: specializationLabels[item.specialization],
declaredGrade: item.declared_grade ? gradeLabels[item.declared_grade] : null,
confirmed: item.confirmation_status === "confirmed",
})) ?? null,
stack: card.stack?.map((tag) => stackLabels[tag]) ?? null,
experience: card.experience_band ? experienceBandLabels[card.experience_band] : null,
workFormats: card.work_formats?.map((format) => workFormatLabels[format]) ?? null,
salaryCompatibility: card.salary_compatibility
? salaryCompatibilityLabels[card.salary_compatibility]
: null,
projects:
card.projects?.map((project) => ({
title: project.title,
description: project.description,
stack: [...project.stack],
repositoryVerified: project.repository_verified,
})) ?? null,
};
}
export type EvidenceFact = {
title: string;
trust: TrustLevelValue;
trustLabel: string;
observedYear: number;
basisLabel: string;
};
const skillLabels: Readonly<Record<EvidenceSkillCode, string>> = {
...specializationLabels,
...stackLabels,
};
const trustViews: Readonly<Record<number, { level: TrustLevelValue; label: string }>> = {
0: { level: "claimed", label: "Заявлено, не подтверждено отдельно" },
1: { level: "partial", label: "Онлайн-результат без подтверждения личности" },
2: { level: "confirmed", label: "Результат привязан к подтвержденной личности" },
3: { level: "confirmed", label: "Очная проверка" },
};
/** Facts of the evidence section as the server lists them, with its basis. */
export function presentEvidence(evidence: OrganizationEvidence): EvidenceFact[] {
return evidence.items.map((fact) => {
const trust = trustViews[fact.trust] ?? trustViews[0]!;
return {
title: `${skillLabels[fact.skill]}: ${gradeLabels[fact.grade]}`,
trust: trust.level,
trustLabel: trust.label,
observedYear: fact.observed_year,
basisLabel: "Результат теста",
};
});
}