forked from jappel/leistungsbilanz-ts
Add print cover fields and office profile
- Project settings gain siteAddress, workStage, projectLead and projectEditor (project.update-settings schema version 3, migration 0009); versions 2 and 1 stay executable and keep the current cover values. Snapshot schema 6 carries the fields; older versions upgrade with null. - Global office profile (office name/address) next to the document logo: table document_branding_settings, PUT /api/document-branding/office, editable from the print view toolbar. - Cover page reads all fields; empty values show the "[ergänzen]" marker. The Planstände editor column shows the project editor. - Shared logo constants moved to a dependency-free module so the Next.js bundler can import them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
94688d7a8c
commit
bf58296ba5
35 changed files with 3571 additions and 106 deletions
|
|
@ -8,6 +8,23 @@ import {
|
|||
} from "../src/domain/models/project-state-snapshot.model.js";
|
||||
import { createNamedProjectSnapshotSchema } from "../src/shared/validation/project-snapshot.schemas.js";
|
||||
|
||||
/** Removes the fields introduced by snapshot schema version 6. */
|
||||
function withoutVersionSixFields<
|
||||
T extends { project: object; distributionBoards: object[] },
|
||||
>(snapshot: T): T {
|
||||
const project = snapshot.project as Record<string, unknown>;
|
||||
for (const field of ["siteAddress", "workStage", "projectLead", "projectEditor"]) {
|
||||
delete project[field];
|
||||
}
|
||||
for (const board of snapshot.distributionBoards) {
|
||||
const record = board as Record<string, unknown>;
|
||||
for (const field of ["boardNumber", "location", "fedFrom", "remark"]) {
|
||||
delete record[field];
|
||||
}
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
function minimalSnapshot() {
|
||||
return {
|
||||
schemaVersion: projectStateSnapshotSchemaVersion,
|
||||
|
|
@ -29,6 +46,10 @@ function minimalSnapshot() {
|
|||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
siteAddress: "Musterstraße 1\n12345 Musterstadt" as string | null,
|
||||
workStage: "LPH 5" as string | null,
|
||||
projectLead: "P. Leitung" as string | null,
|
||||
projectEditor: null as string | null,
|
||||
},
|
||||
distributionBoards: [],
|
||||
externalCsvConfiguration: null,
|
||||
|
|
@ -155,7 +176,7 @@ describe("project state snapshot model", () => {
|
|||
});
|
||||
|
||||
it("upgrades the supported baseline snapshot with a safe building default", () => {
|
||||
const baseline = structuredClone(minimalSnapshot());
|
||||
const baseline = withoutVersionSixFields(structuredClone(minimalSnapshot()));
|
||||
baseline.schemaVersion = 1 as typeof baseline.schemaVersion;
|
||||
delete (baseline.project as Record<string, unknown>).isPublicBuilding;
|
||||
delete (baseline as Record<string, unknown>).externalCsvConfiguration;
|
||||
|
|
@ -169,7 +190,7 @@ describe("project state snapshot model", () => {
|
|||
});
|
||||
|
||||
it("upgrades snapshot version 2 with an empty external CSV configuration", () => {
|
||||
const previous = structuredClone(minimalSnapshot());
|
||||
const previous = withoutVersionSixFields(structuredClone(minimalSnapshot()));
|
||||
previous.schemaVersion = 2 as typeof previous.schemaVersion;
|
||||
delete (previous as Record<string, unknown>).externalCsvConfiguration;
|
||||
delete (previous as Record<string, unknown>).externalModel;
|
||||
|
|
@ -187,7 +208,7 @@ describe("project state snapshot model", () => {
|
|||
});
|
||||
|
||||
it("upgrades snapshot version 3 with an empty external model", () => {
|
||||
const previous = structuredClone(minimalSnapshot());
|
||||
const previous = withoutVersionSixFields(structuredClone(minimalSnapshot()));
|
||||
previous.schemaVersion = 3 as typeof previous.schemaVersion;
|
||||
delete (previous as Record<string, unknown>).externalModel;
|
||||
|
||||
|
|
@ -203,20 +224,22 @@ describe("project state snapshot model", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("upgrades snapshot version 5 with empty distribution-board info", () => {
|
||||
const previous = protectedSnapshot();
|
||||
it("upgrades snapshot version 5 with empty board info and cover fields", () => {
|
||||
const previous = withoutVersionSixFields(protectedSnapshot());
|
||||
previous.schemaVersion = 5 as typeof previous.schemaVersion;
|
||||
for (const board of previous.distributionBoards) {
|
||||
const record = board as Record<string, unknown>;
|
||||
delete record.boardNumber;
|
||||
delete record.location;
|
||||
delete record.fedFrom;
|
||||
delete record.remark;
|
||||
}
|
||||
|
||||
const upgraded = parseProjectStateSnapshot(previous);
|
||||
|
||||
assert.equal(upgraded.schemaVersion, projectStateSnapshotSchemaVersion);
|
||||
assert.deepEqual(
|
||||
{
|
||||
siteAddress: upgraded.project.siteAddress,
|
||||
workStage: upgraded.project.workStage,
|
||||
projectLead: upgraded.project.projectLead,
|
||||
projectEditor: upgraded.project.projectEditor,
|
||||
},
|
||||
{ siteAddress: null, workStage: null, projectLead: null, projectEditor: null }
|
||||
);
|
||||
assert.deepEqual(
|
||||
{
|
||||
boardNumber: upgraded.distributionBoards[0]?.boardNumber,
|
||||
|
|
@ -228,27 +251,26 @@ describe("project state snapshot model", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("keeps distribution-board info values and rejects them in older versions", () => {
|
||||
it("keeps board info and cover values and rejects them in older versions", () => {
|
||||
const parsed = parseProjectStateSnapshot(protectedSnapshot());
|
||||
assert.equal(parsed.distributionBoards[0]?.boardNumber, "UV 1.1");
|
||||
assert.equal(parsed.distributionBoards[0]?.location, "Raum 003 Technik");
|
||||
assert.equal(parsed.distributionBoards[0]?.fedFrom, "HV 0.1");
|
||||
assert.equal(parsed.project.siteAddress, "Musterstraße 1\n12345 Musterstadt");
|
||||
assert.equal(parsed.project.workStage, "LPH 5");
|
||||
|
||||
const mislabeled = protectedSnapshot();
|
||||
mislabeled.schemaVersion = 5 as typeof mislabeled.schemaVersion;
|
||||
assert.throws(() => parseProjectStateSnapshot(mislabeled));
|
||||
|
||||
const missingCover = structuredClone(protectedSnapshot());
|
||||
delete (missingCover.project as Record<string, unknown>).workStage;
|
||||
assert.throws(() => parseProjectStateSnapshot(missingCover));
|
||||
});
|
||||
|
||||
it("upgrades snapshot version 4 with the existing quantity as manual share", () => {
|
||||
const previous = protectedSnapshot();
|
||||
const previous = withoutVersionSixFields(protectedSnapshot());
|
||||
previous.schemaVersion = 4 as typeof previous.schemaVersion;
|
||||
for (const board of previous.distributionBoards) {
|
||||
const record = board as Record<string, unknown>;
|
||||
delete record.boardNumber;
|
||||
delete record.location;
|
||||
delete record.fedFrom;
|
||||
delete record.remark;
|
||||
}
|
||||
previous.circuits[0]!.isReserve = false;
|
||||
previous.circuits[0]!.deviceRows = [{
|
||||
id: "row-1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue