feat(doc): statische map-Methode und iconSrc getter hinzugefügt

- Methode `static map()` hinzugefügt, um eine `Doc`-Instanz aus einem Teilobjekt zu erzeugen.
- Umbenennung des Getters `Extension` in `extension`, um mit den Namenskonventionen übereinzustimmen.
- Getter `iconSrc` hinzugefügt, um einen Dateisymbolpfad basierend auf der Dateierweiterung bereitzustellen.
This commit is contained in:
tekh 2025-07-11 12:43:43 +02:00
parent b9e6ff27db
commit 5e36a978a7
2 changed files with 13 additions and 2 deletions

View File

@ -301,4 +301,4 @@ export const _documents: Doc[] = [
addedWhen: new Date("2024-04-17T11:25:00Z"), addedWhen: new Date("2024-04-17T11:25:00Z"),
addedWho: "SchreiberM" addedWho: "SchreiberM"
} }
].map(doc => Object.assign(doc)); ].map(doc => Doc.map(doc));

View File

@ -1,6 +1,13 @@
import { _documents } from "src/_mock" import { _documents } from "src/_mock"
export class Doc { export class Doc {
static map(source?: Partial<Doc>): Doc {
const doc = new Doc();
Object.assign(doc, source);
return doc;
}
id!: number; id!: number;
name!: string; name!: string;
data!: Uint8Array; data!: Uint8Array;
@ -9,13 +16,17 @@ export class Doc {
changedWhen?: Date; changedWhen?: Date;
changedWho?: string; changedWho?: string;
get Extension(): string | undefined { get extension(): string | undefined {
const parts = this.name.split('.'); const parts = this.name.split('.');
if (parts.length > 1 && parts[parts.length - 1].trim() !== '') { if (parts.length > 1 && parts[parts.length - 1].trim() !== '') {
return parts[parts.length - 1].toLowerCase(); return parts[parts.length - 1].toLowerCase();
} }
return undefined; return undefined;
} }
get iconSrc(): string {
return `assets/icons/file/${this.extension ?? 'unknown'}.svg`;
}
} }
export type DocQuery = { export type DocQuery = {