feat(navigation): add Header entity + use-case + mock/payload repos + DI container

This commit is contained in:
2026-05-05 08:34:14 +02:00
parent f71025b14a
commit 19f32ec94d
10 changed files with 164 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import "reflect-metadata";
import { injectable } from "inversify";
import type { IHeaderRepository } from "../../application/repositories/header-repository.interface";
import type { Header } from "../../entities/header";
@injectable()
export class MockHeaderRepository implements IHeaderRepository {
async getHeader(): Promise<Header> {
return {
items: [
{ label: "Home", href: "/", external: false },
{ label: "Blog", href: "/blog", external: false },
{ label: "About", href: "/about", external: false },
],
};
}
}

View File

@@ -0,0 +1,48 @@
import "reflect-metadata";
import { injectable } from "inversify";
import { getPayload } from "payload";
import type { SanitizedConfig } from "payload";
import type { IHeaderRepository } from "../../application/repositories/header-repository.interface";
import type { Header, HeaderItem } from "../../entities/header";
type PayloadHeaderGlobal = {
logo?: string | number | { id: string | number } | null;
items?: Array<{
label?: string | null;
href?: string | null;
external?: boolean | null;
}> | null;
};
@injectable()
export class PayloadHeaderRepository implements IHeaderRepository {
private config: SanitizedConfig;
constructor(config: SanitizedConfig) {
this.config = config;
}
async getHeader(): Promise<Header> {
const payload = await getPayload({ config: this.config });
const doc = (await payload.findGlobal({
slug: "header",
overrideAccess: false,
})) as PayloadHeaderGlobal;
const logoId =
typeof doc.logo === "object" && doc.logo !== null
? String(doc.logo.id)
: doc.logo != null
? String(doc.logo)
: undefined;
const items: HeaderItem[] = (doc.items ?? []).map((item) => ({
label: item.label ?? "",
href: item.href ?? "",
external: item.external ?? false,
}));
return { logoId, items };
}
}