From bca4b36749eb4e5d5c334cf116c3e099ad0cb833 Mon Sep 17 00:00:00 2001 From: Emanuele Dall'Ara <71103219+LeleDallas@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:54:47 +0200 Subject: [PATCH 1/3] feat(payments): hide notice endpoint --- src/features/payments/routers/notices.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/features/payments/routers/notices.ts b/src/features/payments/routers/notices.ts index 02ad348a..4a8f8e95 100644 --- a/src/features/payments/routers/notices.ts +++ b/src/features/payments/routers/notices.ts @@ -1,13 +1,15 @@ import * as O from "fp-ts/lib/Option"; import { pipe } from "fp-ts/lib/function"; -import NoticesDB from "../persistence/notices"; import { sendFileFromRootPath } from "../../../utils/file"; +import NoticesDB from "../persistence/notices"; import { NoticeListWrapResponse } from "../../../../generated/definitions/pagopa/transactions/NoticeListWrapResponse"; +import { ioDevServerConfig } from "../../../config"; import { addNoticesHandler } from "./router"; const CONTINUATION_TOKEN_HEADER = "x-continuation-token"; const DEFAULT_SIZE = 10; +const { hideReceiptResponseCode } = ioDevServerConfig.features.payments; addNoticesHandler("get", "/paids", (req, res) => { const size = req.query.size ? Number(req.query.size) : DEFAULT_SIZE; @@ -87,3 +89,21 @@ addNoticesHandler("get", "/paids/:eventId/pdf", (req, res) => { ) ); }); + +addNoticesHandler("post", "/paids/:eventId/disable", (req, res) => { + pipe( + req.params.eventId, + O.fromNullable, + O.fold( + () => res.sendStatus(400), + eventId => + pipe( + O.fromNullable(NoticesDB.removeUserNotice(eventId)), + O.fold( + () => res.sendStatus(hideReceiptResponseCode), + () => res.sendStatus(hideReceiptResponseCode) + ) + ) + ) + ); +}); From 2519b9e07873f330e1fc071792a198c90b3e8495 Mon Sep 17 00:00:00 2001 From: Emanuele Dall'Ara <71103219+LeleDallas@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:56:12 +0200 Subject: [PATCH 2/3] refactor(config): mock for hide notice endpoint --- src/config.ts | 3 ++- src/types/config.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index c789693e..56923d8a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -177,7 +177,8 @@ const defaultConfig: IoDevServerConfig = { }, features: { payments: { - numberOfTransactions: 12 + numberOfTransactions: 12, + hideReceiptResponseCode: 400 }, bonus: { cgn: { diff --git a/src/types/config.ts b/src/types/config.ts index 90d041e4..ffd2018b 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -192,7 +192,9 @@ export const IoDevServerConfig = t.interface({ t.interface({ payments: t.interface({ // the number of transactions to generate at the beginning - numberOfTransactions: t.number + numberOfTransactions: t.number, + // the response code when hiding a receipt + hideReceiptResponseCode: HttpResponseCode }), bonus: t.interface({ // defines the special configuration for cgn eligibility From f73e3240d2607c3e2fce5cf323ef20f7470bed7c Mon Sep 17 00:00:00 2001 From: Emanuele Dall'Ara <71103219+LeleDallas@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:15:20 +0100 Subject: [PATCH 3/3] refactor: removed useless nested fold --- src/features/payments/routers/notices.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/features/payments/routers/notices.ts b/src/features/payments/routers/notices.ts index 4a8f8e95..f2839e4c 100644 --- a/src/features/payments/routers/notices.ts +++ b/src/features/payments/routers/notices.ts @@ -96,14 +96,10 @@ addNoticesHandler("post", "/paids/:eventId/disable", (req, res) => { O.fromNullable, O.fold( () => res.sendStatus(400), - eventId => - pipe( - O.fromNullable(NoticesDB.removeUserNotice(eventId)), - O.fold( - () => res.sendStatus(hideReceiptResponseCode), - () => res.sendStatus(hideReceiptResponseCode) - ) - ) + eventId => { + NoticesDB.removeUserNotice(eventId); + return res.sendStatus(hideReceiptResponseCode); + } ) ); });