From d73fa2f4d141bbdd349dd8e8abacfc53032ef64d Mon Sep 17 00:00:00 2001 From: Gabriel Juchault Date: Thu, 11 Jan 2024 16:24:14 +0100 Subject: [PATCH] fix: even less factories --- .../__tests__/get-healthcheck.test.ts | 2 +- src/presentation/http/index.ts | 8 +--- .../http/routes/healthcheck/index.ts | 38 +++++++++---------- src/repository/healthcheck/index.ts | 6 --- src/repository/index.ts | 5 +++ src/store.ts | 6 ++- src/test-helpers/mock.ts | 3 +- 7 files changed, 30 insertions(+), 38 deletions(-) create mode 100644 src/repository/index.ts diff --git a/src/application/healthcheck/__tests__/get-healthcheck.test.ts b/src/application/healthcheck/__tests__/get-healthcheck.test.ts index 3220aa9c..73263bad 100644 --- a/src/application/healthcheck/__tests__/get-healthcheck.test.ts +++ b/src/application/healthcheck/__tests__/get-healthcheck.test.ts @@ -4,7 +4,7 @@ import { before, describe, it, mock } from "node:test"; import type { Redis } from "ioredis"; import { err, ok } from "neverthrow"; -import type { HealthcheckRepository } from "~/repository/healthcheck/index.js"; +import { HealthcheckRepository } from "~/repository/index.js"; import { buildMockDependencyStore } from "~/test-helpers/mock.js"; import type { GetHealthcheckResult } from "../get-healthcheck.js"; diff --git a/src/presentation/http/index.ts b/src/presentation/http/index.ts index 7fc4bfa2..0f5cd173 100644 --- a/src/presentation/http/index.ts +++ b/src/presentation/http/index.ts @@ -4,7 +4,7 @@ import { initServer } from "@ts-rest/fastify"; import { DependencyStore } from "~/store.js"; import { - bindHealthcheckRoutes, + getHealthcheckRoute, healthcheckRouterContract, } from "./routes/healthcheck/index.js"; @@ -24,11 +24,7 @@ export function createAppRouter({ }: { dependencyStore: DependencyStore; }) { - const healthcheckRouter = bindHealthcheckRoutes({ - dependencyStore, - }); - return s.router(contract, { - ...healthcheckRouter, + getHealthcheck: () => getHealthcheckRoute({ dependencyStore }), }); } diff --git a/src/presentation/http/routes/healthcheck/index.ts b/src/presentation/http/routes/healthcheck/index.ts index 83337744..97734fe1 100644 --- a/src/presentation/http/routes/healthcheck/index.ts +++ b/src/presentation/http/routes/healthcheck/index.ts @@ -40,32 +40,28 @@ export const healthcheckRouterContract = { }, } as const; -export function bindHealthcheckRoutes({ +export async function getHealthcheckRoute({ dependencyStore, }: { dependencyStore: DependencyStore; -}) { - return { - async getHealthcheck(): Promise { - const healthcheck = await getHealthcheck({ dependencyStore }); +}): Promise { + const healthcheck = await getHealthcheck({ dependencyStore }); - if (!isHealthcheckFullyHealthy(healthcheck)) { - return { - status: 500, - body: { - ...healthcheck, - http: "healthy", - }, - }; - } + if (!isHealthcheckFullyHealthy(healthcheck)) { + return { + status: 500, + body: { + ...healthcheck, + http: "healthy", + }, + }; + } - return { - status: 200, - body: { - ...healthcheck, - http: "healthy", - }, - }; + return { + status: 200, + body: { + ...healthcheck, + http: "healthy", }, }; } diff --git a/src/repository/healthcheck/index.ts b/src/repository/healthcheck/index.ts index 1747db91..9cd70a12 100644 --- a/src/repository/healthcheck/index.ts +++ b/src/repository/healthcheck/index.ts @@ -4,12 +4,6 @@ import { z } from "zod"; import { DependencyStore } from "~/store"; -export interface HealthcheckRepository { - getHealthcheck(_: { - dependencyStore: DependencyStore; - }): Promise; -} - export type GetHealthcheckResult = Result<"healthy", "databaseError">; export async function getHealthcheck({ diff --git a/src/repository/index.ts b/src/repository/index.ts new file mode 100644 index 00000000..45ee8a71 --- /dev/null +++ b/src/repository/index.ts @@ -0,0 +1,5 @@ +import * as healthcheckRepository from "./healthcheck/index.js"; +import * as userRepository from "./user/index.js"; + +export type HealthcheckRepository = typeof healthcheckRepository; +export type UserRepository = typeof userRepository; diff --git a/src/store.ts b/src/store.ts index 41060b60..fff42d4e 100644 --- a/src/store.ts +++ b/src/store.ts @@ -3,8 +3,10 @@ import { DependencyStore as SdkDependencyStore, } from "@gjuchault/typescript-service-sdk"; -import type { HealthcheckRepository } from "./repository/healthcheck/index.js"; -import type { UserRepository } from "./repository/user/index.js"; +import type { + HealthcheckRepository, + UserRepository, +} from "~/repository/index.js"; type ExtraDependencies = { healthcheckRepository: HealthcheckRepository; diff --git a/src/test-helpers/mock.ts b/src/test-helpers/mock.ts index 5cfff515..82dcdc1b 100644 --- a/src/test-helpers/mock.ts +++ b/src/test-helpers/mock.ts @@ -12,8 +12,7 @@ import type { } from "@gjuchault/typescript-service-sdk"; import { createMockLoggerProvider } from "@gjuchault/typescript-service-sdk"; -import type { HealthcheckRepository } from "~/repository/healthcheck"; -import type { UserRepository } from "~/repository/user"; +import { HealthcheckRepository, UserRepository } from "~/repository/index.js"; import { createAppDependencyStore } from "~/store"; export function buildMock(initialImplementation: Partial = {}): T {