fix(eoc-push): interpolera {brand} + EOC-tone i pushad wall
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Redis } from "ioredis";
|
||||
import BRAND from "../../../../brand.config.json" with { type: "json" };
|
||||
import { CACHE_KEY } from "./ops-summary.js";
|
||||
|
||||
export interface EocPushResult {
|
||||
@@ -29,9 +30,40 @@ interface EocFeedback {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface EocTile {
|
||||
label: string;
|
||||
value: string;
|
||||
tone?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface EocBoard {
|
||||
title: string;
|
||||
tiles: EocTile[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface EocWall {
|
||||
boards: EocBoard[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface EocQueue {
|
||||
workers_ok?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface EocSafety {
|
||||
allergen_invariant_brott?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a payload that matches EOC's authoritative contract:
|
||||
* feedback.senaste[].created_at must be sent as feedback.senaste[].skapad.
|
||||
* - feedback.senaste[].created_at must be sent as feedback.senaste[].skapad.
|
||||
* - wall.boards[].title interpolates {brand} with the brand name.
|
||||
* - wall tile tones use EOC vocabulary (good|warn|crit|"").
|
||||
* - Workers and Allergen-brott tiles can escalate to "crit" from flat fields.
|
||||
* All other keys are forwarded unchanged.
|
||||
*/
|
||||
function mapPayloadForEoc(parsed: Record<string, unknown>): Record<string, unknown> {
|
||||
@@ -49,6 +81,33 @@ function mapPayloadForEoc(parsed: Record<string, unknown>): Record<string, unkno
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const wall = mapped.wall as EocWall | undefined;
|
||||
if (wall && Array.isArray(wall.boards)) {
|
||||
const jobb = mapped.jobb as EocQueue | undefined;
|
||||
const sakerhet = mapped.sakerhet as EocSafety | undefined;
|
||||
const workersDown = jobb?.workers_ok === false;
|
||||
const allergenBreach = (sakerhet?.allergen_invariant_brott ?? 0) > 0;
|
||||
|
||||
mapped.wall = {
|
||||
...wall,
|
||||
boards: wall.boards.map((board) => ({
|
||||
...board,
|
||||
title: board.title.replace(/\{brand\}/g, BRAND.name),
|
||||
tiles: board.tiles.map((tile) => {
|
||||
let tone = tile.tone === "ok" ? "good" : tile.tone;
|
||||
if (tile.label === "Workers" && workersDown) {
|
||||
tone = "crit";
|
||||
}
|
||||
if (tile.label === "Allergen-brott" && allergenBreach) {
|
||||
tone = "crit";
|
||||
}
|
||||
return { ...tile, tone };
|
||||
}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user