import { eq } from "drizzle-orm"; import type { AppDatabase } from "../database-context.js"; import { documentBrandingAssets, type DocumentBrandingAsset, } from "../schema/document-branding-assets.js"; // Plain repository without revision semantics: branding is global office // configuration, not a project mutation. export class DocumentBrandingRepository { constructor(private readonly db: AppDatabase) {} get(key: string): DocumentBrandingAsset | undefined { return this.db .select() .from(documentBrandingAssets) .where(eq(documentBrandingAssets.key, key)) .get(); } upsert(asset: { key: string; mimeType: string; fileName: string | null; data: Buffer; }): DocumentBrandingAsset { const updatedAt = new Date(); return this.db .insert(documentBrandingAssets) .values({ ...asset, updatedAt }) .onConflictDoUpdate({ target: documentBrandingAssets.key, set: { mimeType: asset.mimeType, fileName: asset.fileName, data: asset.data, updatedAt, }, }) .returning() .get(); } delete(key: string): boolean { return ( this.db .delete(documentBrandingAssets) .where(eq(documentBrandingAssets.key, key)) .run().changes > 0 ); } }