Skip to content

Commit

Permalink
fix: even less factories
Browse files Browse the repository at this point in the history
  • Loading branch information
gjuchault committed Jan 15, 2024
1 parent 86781a6 commit d73fa2f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 2 additions & 6 deletions src/presentation/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { initServer } from "@ts-rest/fastify";
import { DependencyStore } from "~/store.js";

import {
bindHealthcheckRoutes,
getHealthcheckRoute,
healthcheckRouterContract,
} from "./routes/healthcheck/index.js";

Expand All @@ -24,11 +24,7 @@ export function createAppRouter({
}: {
dependencyStore: DependencyStore;
}) {
const healthcheckRouter = bindHealthcheckRoutes({
dependencyStore,
});

return s.router(contract, {
...healthcheckRouter,
getHealthcheck: () => getHealthcheckRoute({ dependencyStore }),
});
}
38 changes: 17 additions & 21 deletions src/presentation/http/routes/healthcheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,28 @@ export const healthcheckRouterContract = {
},
} as const;

export function bindHealthcheckRoutes({
export async function getHealthcheckRoute({
dependencyStore,
}: {
dependencyStore: DependencyStore;
}) {
return {
async getHealthcheck(): Promise<RouterGetHealthcheckResult> {
const healthcheck = await getHealthcheck({ dependencyStore });
}): Promise<RouterGetHealthcheckResult> {
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",
},
};
}
Expand Down
6 changes: 0 additions & 6 deletions src/repository/healthcheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { z } from "zod";

import { DependencyStore } from "~/store";

export interface HealthcheckRepository {
getHealthcheck(_: {
dependencyStore: DependencyStore;
}): Promise<GetHealthcheckResult>;
}

export type GetHealthcheckResult = Result<"healthy", "databaseError">;

export async function getHealthcheck({
Expand Down
5 changes: 5 additions & 0 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 4 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/test-helpers/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(initialImplementation: Partial<T> = {}): T {
Expand Down

0 comments on commit d73fa2f

Please sign in to comment.