Skip to content

Commit

Permalink
Replace old logic and parse path parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
kin0992 committed Jan 15, 2025
1 parent b210351 commit 6e1fc95
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apps/to-do-api/src/adapters/azure/functions/delete-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { httpAzureFunction } from "@pagopa/handler-kit-azure-func";
import * as RTE from "fp-ts/lib/ReaderTaskEither.js";
import { pipe } from "fp-ts/lib/function.js";

import { aTask } from "../../../domain/__tests__/data.js";
import { Capabilities } from "../../../domain/Capabilities.js";
import { TaskIdCodec } from "../../../domain/Task.js";
import { deleteTask } from "../../../domain/TaskRepository.js";
import { toHttpProblemJson } from "../../http/codec.js";
import { parsePathParameter } from "../../http/middleware.js";

type Env = Pick<Capabilities, "taskIdGenerator" | "taskRepository">;

Expand All @@ -15,11 +16,14 @@ const makeHandlerKitHandler: H.Handler<
| H.HttpResponse<H.ProblemJson, H.HttpErrorStatusCode>
| H.HttpResponse<unknown, 204>,
Env
> = H.of(() =>
> = H.of((req: H.HttpRequest) =>
pipe(
RTE.ask<Env>(),
// validate request body
RTE.apSW("id", RTE.of(aTask.id)),
RTE.apSW(
"id",
RTE.fromEither(parsePathParameter(TaskIdCodec, "taskId")(req)),
),
// execute use case
RTE.flatMap(({ id }) => deleteTask(id)),
// handle result and prepare response
Expand Down

0 comments on commit 6e1fc95

Please sign in to comment.