leistungsbilanz-ts/src/db/repositories/project.repository.ts
Grovy311 bf58296ba5 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>
2026-09-25 20:42:53 +02:00

49 lines
1.6 KiB
TypeScript

import crypto from "node:crypto";
import { eq } from "drizzle-orm";
import type { AppDatabase } from "../database-context.js";
import { projects } from "../schema/projects.js";
import type {
CreateProjectInput,
} from "../../shared/validation/project-structure.schemas.js";
import { defaultDistributionBoardSupplyTypes } from "../../shared/constants/distribution-board.js";
export class ProjectRepository {
constructor(private readonly database: AppDatabase) {}
async list() {
const db = this.database;
return db.select().from(projects);
}
async create(input: CreateProjectInput) {
const db = this.database;
const id = crypto.randomUUID();
const project = {
id,
name: input.name,
internalProjectNumber: input.internalProjectNumber ?? null,
externalProjectNumber: input.externalProjectNumber ?? null,
buildingOwner: input.buildingOwner ?? null,
description: input.description ?? null,
isPublicBuilding: input.isPublicBuilding ?? false,
singlePhaseVoltageV: input.singlePhaseVoltageV ?? 230,
threePhaseVoltageV: input.threePhaseVoltageV ?? 400,
enabledDistributionBoardSupplyTypes: [
...defaultDistributionBoardSupplyTypes,
],
siteAddress: null,
workStage: null,
projectLead: null,
projectEditor: null,
currentRevision: 0,
};
await db.insert(projects).values(project);
return project;
}
async findById(projectId: string) {
const db = this.database;
const [row] = await db.select().from(projects).where(eq(projects.id, projectId)).limit(1);
return row ?? null;
}
}