Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [IOBP-838] Remove receipt from list endpoint #430

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ const defaultConfig: IoDevServerConfig = {
},
features: {
payments: {
numberOfTransactions: 12
numberOfTransactions: 12,
hideReceiptResponseCode: 400
},
bonus: {
cgn: {
Expand Down
22 changes: 21 additions & 1 deletion src/features/payments/routers/notices.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
)
)
)
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't really need two nested fold that have the same behavior, what do you think of replacing with the following suggestion?

Suggested change
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)
)
)
)
);
});
addNoticesHandler("post", "/paids/:eventId/disable", (req, res) => {
pipe(
req.params.eventId,
O.fromNullable,
O.fold(
() => res.sendStatus(400),
eventId => {
NoticesDB.removeUserNotice(eventId);
return res.sendStatus(hideReceiptResponseCode);
}
)
);
});

4 changes: 3 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading