feat(navigation): add controller + tRPC router + header global + barrel
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
export {};
|
export type { Header, HeaderItem } from "./entities/header";
|
||||||
|
export { headerQuery } from "./ui/query";
|
||||||
|
|||||||
28
packages/navigation/src/integrations/api/router.test.ts
Normal file
28
packages/navigation/src/integrations/api/router.test.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import { navigationContainer } from "@/di/container";
|
||||||
|
import { NAVIGATION_SYMBOLS } from "@/di/symbols";
|
||||||
|
import { MockHeaderRepository } from "@/infrastructure/repositories/mock-header.repository";
|
||||||
|
import type { IHeaderRepository } from "@/application/repositories/header-repository.interface";
|
||||||
|
import { navigationRouter } from "./router";
|
||||||
|
|
||||||
|
describe("navigationRouter", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
if (navigationContainer.isBound(NAVIGATION_SYMBOLS.IHeaderRepository)) {
|
||||||
|
navigationContainer.unbind(NAVIGATION_SYMBOLS.IHeaderRepository);
|
||||||
|
}
|
||||||
|
navigationContainer
|
||||||
|
.bind<IHeaderRepository>(NAVIGATION_SYMBOLS.IHeaderRepository)
|
||||||
|
.toConstantValue(new MockHeaderRepository());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes header procedure", () => {
|
||||||
|
const names = Object.keys(navigationRouter._def.procedures);
|
||||||
|
expect(names).toContain("header");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("header returns 3 items", async () => {
|
||||||
|
const caller = navigationRouter.createCaller({});
|
||||||
|
const result = await caller.header();
|
||||||
|
expect(result.items).toHaveLength(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
8
packages/navigation/src/integrations/api/router.ts
Normal file
8
packages/navigation/src/integrations/api/router.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { router, publicProcedure } from "@repo/core-shared/trpc/init";
|
||||||
|
import { getHeaderController } from "../../interface-adapters/controllers/header.controller";
|
||||||
|
|
||||||
|
export const navigationRouter = router({
|
||||||
|
header: publicProcedure.query(() => getHeaderController()),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type NavigationRouter = typeof navigationRouter;
|
||||||
24
packages/navigation/src/integrations/cms/globals/header.ts
Normal file
24
packages/navigation/src/integrations/cms/globals/header.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import type { GlobalConfig } from "payload";
|
||||||
|
|
||||||
|
export const header: GlobalConfig = {
|
||||||
|
slug: "header",
|
||||||
|
admin: {
|
||||||
|
group: "Navigation",
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "logo",
|
||||||
|
type: "upload",
|
||||||
|
relationTo: "media",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "items",
|
||||||
|
type: "array",
|
||||||
|
fields: [
|
||||||
|
{ name: "label", type: "text", required: true },
|
||||||
|
{ name: "href", type: "text", required: true },
|
||||||
|
{ name: "external", type: "checkbox", defaultValue: false },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
1
packages/navigation/src/integrations/cms/index.ts
Normal file
1
packages/navigation/src/integrations/cms/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { header } from "./globals/header";
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import type { Header } from "../../entities/header";
|
||||||
|
import { getHeaderUseCase } from "../../application/use-cases/get-header.use-case";
|
||||||
|
|
||||||
|
export async function getHeaderController(): Promise<Header> {
|
||||||
|
return getHeaderUseCase();
|
||||||
|
}
|
||||||
9
packages/navigation/src/ui/query.ts
Normal file
9
packages/navigation/src/ui/query.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
type TrpcClient = {
|
||||||
|
navigation: {
|
||||||
|
header: { queryOptions: () => unknown };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function headerQuery(client: TrpcClient) {
|
||||||
|
return client.navigation.header.queryOptions();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user