From 8c5cbfe92718325a301ef8c413fb4ef51d195b6f Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 16 Oct 2024 15:49:12 +0200 Subject: [PATCH 1/9] chore: Adapt new openAPI biz-events --- package.json | 2 +- .../payments/persistence/transactions.ts | 34 ++++++++++--------- src/features/payments/routers/transactions.ts | 11 +++--- src/features/payments/utils/transactions.ts | 10 +++--- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 4d221e06..58b08a5b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "api_trial_system": "https://raw.githubusercontent.com/pagopa/io-backend/v14.3.0-RELEASE/api_trial_system.yaml", "api_pagopa_walletv3": "https://raw.githubusercontent.com/pagopa/pagopa-infra/v1.202.0/src/domains/pay-wallet-app/api/io-payment-wallet/v1/_openapi.json.tpl", "api_pagopa_ecommerce": "https://raw.githubusercontent.com/pagopa/pagopa-infra/v1.202.0/src/domains/ecommerce-app/api/ecommerce-io/v2/_openapi.json.tpl", - "api_pagopa_biz_events": "https://raw.githubusercontent.com/pagopa/pagopa-biz-events-service/0.1.37/openapi/openapi_io_patch.json", + "api_pagopa_biz_events": "https://raw.githubusercontent.com/pagopa/pagopa-biz-events-service/0.1.57/openapi/openapi_io_patch_lap.json", "api_pagopa_platform": "https://raw.githubusercontent.com/pagopa/pagopa-infra/v1.64.0/src/domains/shared-app/api/session-wallet/v1/_openapi.json.tpl", "api_services": "https://raw.githubusercontent.com/pagopa/io-backend/master/api_services_app_backend.yaml", "author": "Matteo Boschi", diff --git a/src/features/payments/persistence/transactions.ts b/src/features/payments/persistence/transactions.ts index d6f39a2d..b1fa31fd 100644 --- a/src/features/payments/persistence/transactions.ts +++ b/src/features/payments/persistence/transactions.ts @@ -1,18 +1,18 @@ import { faker } from "@faker-js/faker"; import { pipe } from "fp-ts/lib/function"; import * as O from "fp-ts/lib/Option"; -import { TransactionListItem } from "../../../../generated/definitions/pagopa/transactions/TransactionListItem"; -import { TransactionDetailResponse } from "../../../../generated/definitions/pagopa/transactions/TransactionDetailResponse"; +import { NoticeListItem } from "../../../../generated/definitions/pagopa/transactions/NoticeListItem"; +import { NoticeDetailResponse } from "../../../../generated/definitions/pagopa/transactions/NoticeDetailResponse"; import { TransactionInfo } from "../../../../generated/definitions/pagopa/ecommerce/TransactionInfo"; import { generateRandomInfoTransaction } from "../utils/transactions"; import { ioDevServerConfig } from "../../../config"; const mockedTaxCodes = ["1199250158", "13756881002", "262700362", "31500945"]; -type TransactionId = TransactionListItem["transactionId"]; +type TransactionId = NoticeListItem["eventId"]; -const userTransactions = new Map(); -const transactions = new Map(); +const userTransactions = new Map(); +const transactions = new Map(); const getUserTransactions = () => Array.from(userTransactions.size > 0 ? userTransactions.values() : []); @@ -24,8 +24,8 @@ const getTransactionDetails = (transactionId: TransactionId) => O.chain(transactions => O.fromNullable(transactions.get(transactionId))) ); -const addUserTransaction = (transaction: TransactionListItem) => { - userTransactions.set(transaction.transactionId, transaction); +const addUserTransaction = (transaction: NoticeListItem) => { + userTransactions.set(transaction.eventId, transaction); }; const removeUserTransaction = (transactionId: TransactionId) => { @@ -35,7 +35,7 @@ const removeUserTransaction = (transactionId: TransactionId) => { const addTransactionDetails = ( transactionId: TransactionId, - transaction: TransactionDetailResponse + transaction: NoticeDetailResponse ) => { transactions.set(transactionId, transaction); }; @@ -45,7 +45,7 @@ const removeTransactionDetails = (transactionId: TransactionId) => { }; const generateUserTransaction = ( - transactionId: TransactionId, + eventId: TransactionId, idx: number, additionalTransactionInfo: Partial = {} ) => { @@ -53,12 +53,14 @@ const generateUserTransaction = ( mockedTaxCodes[ faker.datatype.number({ min: 0, max: mockedTaxCodes.length - 1 }) ]; - const randomTransaction: TransactionListItem = { - transactionId, + const randomTransaction: NoticeListItem = { + eventId, payeeName: faker.company.name(), payeeTaxCode, - amount: additionalTransactionInfo.payments?.[0]?.amount.toString(), - transactionDate: new Date( + isDebtor: false, + isPayer: true, + amount: additionalTransactionInfo.payments?.[0]?.amount.toString() || "", + noticeDate: new Date( new Date().setDate(new Date().getDate() - 2 * idx) ).toISOString(), isCart: false @@ -91,11 +93,11 @@ const generateUserTransaction = ( .toString(); addUserTransaction(randomTransaction); - const randomTransactionDetails: TransactionDetailResponse = { - infoTransaction: generateRandomInfoTransaction(cartList), + const randomTransactionDetails: NoticeDetailResponse = { + infoNotice: generateRandomInfoTransaction(cartList), carts: cartList }; - addTransactionDetails(transactionId, randomTransactionDetails); + addTransactionDetails(eventId, randomTransactionDetails); return randomTransaction; }; diff --git a/src/features/payments/routers/transactions.ts b/src/features/payments/routers/transactions.ts index 83e69786..811285c6 100644 --- a/src/features/payments/routers/transactions.ts +++ b/src/features/payments/routers/transactions.ts @@ -3,7 +3,7 @@ import { pipe } from "fp-ts/lib/function"; import TransactionsDB from "../persistence/transactions"; import { sendFileFromRootPath } from "../../../utils/file"; -import { TransactionListWrapResponse } from "../../../../generated/definitions/pagopa/transactions/TransactionListWrapResponse"; +import { NoticeListWrapResponse } from "../../../../generated/definitions/pagopa/transactions/NoticeListWrapResponse"; import { addTransactionHandler } from "./router"; const CONTINUATION_TOKEN_HEADER = "x-continuation-token"; @@ -15,18 +15,15 @@ addTransactionHandler("get", "/transactions", (req, res) => { req.headers[CONTINUATION_TOKEN_HEADER] !== "undefined" ? Number(req.headers[CONTINUATION_TOKEN_HEADER]) : 0; - const response: TransactionListWrapResponse = { - transactions: TransactionsDB.getUserTransactions().slice( - offset, - offset + size - ) + const response: NoticeListWrapResponse = { + notices: TransactionsDB.getUserTransactions().slice(offset, offset + size) }; const continuationToken = TransactionsDB.getUserTransactions().length > offset + size ? (offset + size).toString() : undefined; pipe( - response.transactions, + response.notices, O.fromNullable, O.chain(O.fromPredicate(transactions => transactions.length > 0)), O.fold( diff --git a/src/features/payments/utils/transactions.ts b/src/features/payments/utils/transactions.ts index 9f916a85..5769dcf3 100644 --- a/src/features/payments/utils/transactions.ts +++ b/src/features/payments/utils/transactions.ts @@ -1,10 +1,10 @@ import { faker } from "@faker-js/faker"; import { ulid } from "ulid"; import { - InfoTransactionView, + InfoNotice, OriginEnum, PaymentMethodEnum -} from "../../../../generated/definitions/pagopa/transactions/InfoTransactionView"; +} from "../../../../generated/definitions/pagopa/transactions/InfoNotice"; import { CartItem } from "../../../../generated/definitions/pagopa/transactions/CartItem"; export const PAYMENT_METHODS_TRANSACTIONS_MOCK = [ @@ -43,15 +43,15 @@ export const PAYMENT_METHODS_TRANSACTIONS_MOCK = [ export const generateRandomInfoTransaction = ( cartList: CartItem[], transactionId?: string -): InfoTransactionView => { +): InfoNotice => { const randomPaymentMethod = faker.helpers.arrayElement( PAYMENT_METHODS_TRANSACTIONS_MOCK ); return { - transactionId: transactionId ?? ulid(), + eventId: transactionId ?? ulid(), authCode: faker.random.alphaNumeric(6), rrn: faker.random.numeric(12), - transactionDate: new Date().toISOString(), + noticeDate: new Date().toISOString(), pspName: "Intesa Sanpaolo", walletInfo: { accountHolder: faker.name.fullName(), From 56183f60e152e3cbc717258f730a1f13a8f43bf1 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 16 Oct 2024 15:58:21 +0200 Subject: [PATCH 2/9] chore: Changed route --- src/features/payments/routers/transactions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/payments/routers/transactions.ts b/src/features/payments/routers/transactions.ts index 811285c6..f559d44c 100644 --- a/src/features/payments/routers/transactions.ts +++ b/src/features/payments/routers/transactions.ts @@ -43,7 +43,7 @@ addTransactionHandler("get", "/transactions", (req, res) => { ); }); -addTransactionHandler("get", "/transactions/:transactionId", (req, res) => { +addTransactionHandler("get", "/paids/:transactionId", (req, res) => { pipe( req.params.transactionId, O.fromNullable, @@ -63,7 +63,7 @@ addTransactionHandler("get", "/transactions/:transactionId", (req, res) => { ); }); -addTransactionHandler("get", "/transactions/:transactionId/pdf", (req, res) => { +addTransactionHandler("get", "/paids/:transactionId/pdf", (req, res) => { pipe( req.params.transactionId, O.fromNullable, From 36d36e177441507a557a5317122e434377053838 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 16 Oct 2024 16:00:13 +0200 Subject: [PATCH 3/9] chore: edit baseurl --- src/features/payments/routers/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/payments/routers/router.ts b/src/features/payments/routers/router.ts index 470954b9..e6aad8c8 100644 --- a/src/features/payments/routers/router.ts +++ b/src/features/payments/routers/router.ts @@ -5,7 +5,7 @@ export const walletRouter = Router(); export const PAYMENT_WALLET_PREFIX = "/io-payment-wallet/v1"; export const ECOMMERCE_PREFIX = "/ecommerce/io/v2"; -export const TRANSACTIONS_PREFIX = "/bizevents/tx-service-jwt/v1"; +export const TRANSACTIONS_PREFIX = "/bizevents/notices-service-jwt/v1"; export const PLATFORM_PREFIX = "/session-wallet/v1"; export const addPaymentWalletPrefix = (path: string) => From 806ed6fdd4081f0b0b1b5cc219f9f061af4243b4 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Wed, 16 Oct 2024 16:03:04 +0200 Subject: [PATCH 4/9] chore: edit api path from transactions to paids --- src/features/payments/routers/transactions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/payments/routers/transactions.ts b/src/features/payments/routers/transactions.ts index f559d44c..ef860da7 100644 --- a/src/features/payments/routers/transactions.ts +++ b/src/features/payments/routers/transactions.ts @@ -8,7 +8,7 @@ import { addTransactionHandler } from "./router"; const CONTINUATION_TOKEN_HEADER = "x-continuation-token"; -addTransactionHandler("get", "/transactions", (req, res) => { +addTransactionHandler("get", "/paids", (req, res) => { const size = req.query.size ? Number(req.query.size) : 10; const offset = req.headers[CONTINUATION_TOKEN_HEADER] !== undefined && From 51178e7c83c603925f1560b685ce273c9af7e631 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 17 Oct 2024 12:38:34 +0200 Subject: [PATCH 5/9] chore: Replaced `transaction` occurrences with `notice` --- .../{transactions.ts => notices.ts} | 79 +++++++++---------- .../routers/{transactions.ts => notices.ts} | 26 +++--- src/features/payments/routers/payment.ts | 4 +- src/features/payments/routers/router.ts | 10 +-- src/features/payments/utils/transactions.ts | 6 +- 5 files changed, 60 insertions(+), 65 deletions(-) rename src/features/payments/persistence/{transactions.ts => notices.ts} (53%) rename src/features/payments/routers/{transactions.ts => notices.ts} (72%) diff --git a/src/features/payments/persistence/transactions.ts b/src/features/payments/persistence/notices.ts similarity index 53% rename from src/features/payments/persistence/transactions.ts rename to src/features/payments/persistence/notices.ts index b1fa31fd..afaaf581 100644 --- a/src/features/payments/persistence/transactions.ts +++ b/src/features/payments/persistence/notices.ts @@ -4,48 +4,45 @@ import * as O from "fp-ts/lib/Option"; import { NoticeListItem } from "../../../../generated/definitions/pagopa/transactions/NoticeListItem"; import { NoticeDetailResponse } from "../../../../generated/definitions/pagopa/transactions/NoticeDetailResponse"; import { TransactionInfo } from "../../../../generated/definitions/pagopa/ecommerce/TransactionInfo"; -import { generateRandomInfoTransaction } from "../utils/transactions"; +import { generateRandomInfoNotice } from "../utils/transactions"; import { ioDevServerConfig } from "../../../config"; const mockedTaxCodes = ["1199250158", "13756881002", "262700362", "31500945"]; -type TransactionId = NoticeListItem["eventId"]; +type EventId = NoticeListItem["eventId"]; -const userTransactions = new Map(); -const transactions = new Map(); +const userNotices = new Map(); +const notices = new Map(); -const getUserTransactions = () => - Array.from(userTransactions.size > 0 ? userTransactions.values() : []); +const getUserNotices = () => + Array.from(userNotices.size > 0 ? userNotices.values() : []); -const getTransactionDetails = (transactionId: TransactionId) => +const getNoticeDetails = (eventId: EventId) => pipe( - transactions, + notices, O.fromNullable, - O.chain(transactions => O.fromNullable(transactions.get(transactionId))) + O.chain(notices => O.fromNullable(notices.get(eventId))) ); -const addUserTransaction = (transaction: NoticeListItem) => { - userTransactions.set(transaction.eventId, transaction); +const addUserNotice = (transaction: NoticeListItem) => { + userNotices.set(transaction.eventId, transaction); }; -const removeUserTransaction = (transactionId: TransactionId) => { - userTransactions.delete(transactionId); - removeTransactionDetails(transactionId); +const removeUserNotice = (eventId: EventId) => { + userNotices.delete(eventId); + removeNoticeDetails(eventId); }; -const addTransactionDetails = ( - transactionId: TransactionId, - transaction: NoticeDetailResponse -) => { - transactions.set(transactionId, transaction); +const addNoticeDetails = (eventId: EventId, notice: NoticeDetailResponse) => { + notices.set(eventId, notice); }; -const removeTransactionDetails = (transactionId: TransactionId) => { - transactions.delete(transactionId); +const removeNoticeDetails = (eventId: EventId) => { + notices.delete(eventId); }; -const generateUserTransaction = ( - eventId: TransactionId, +const generateUserNotice = ( + eventId: EventId, idx: number, additionalTransactionInfo: Partial = {} ) => { @@ -53,7 +50,7 @@ const generateUserTransaction = ( mockedTaxCodes[ faker.datatype.number({ min: 0, max: mockedTaxCodes.length - 1 }) ]; - const randomTransaction: NoticeListItem = { + const randomNotice: NoticeListItem = { eventId, payeeName: faker.company.name(), payeeTaxCode, @@ -72,8 +69,8 @@ const generateUserTransaction = ( subject: faker.lorem.sentence(faker.datatype.number({ min: 2, max: 4 })), amount: faker.finance.amount(1, 1000), payee: { - name: randomTransaction.payeeName, - taxCode: randomTransaction.payeeTaxCode + name: randomNotice.payeeName, + taxCode: randomNotice.payeeTaxCode }, debtor: { name: faker.name.fullName(), @@ -86,39 +83,39 @@ const generateUserTransaction = ( }) ); // eslint-disable-next-line functional/immutable-data - randomTransaction.isCart = cartList.length > 1; + randomNotice.isCart = cartList.length > 1; // eslint-disable-next-line functional/immutable-data - randomTransaction.amount = cartList + randomNotice.amount = cartList .reduce((acc, item) => acc + Number(item.amount), 0) .toString(); - addUserTransaction(randomTransaction); + addUserNotice(randomNotice); - const randomTransactionDetails: NoticeDetailResponse = { - infoNotice: generateRandomInfoTransaction(cartList), + const randomNoticeDetails: NoticeDetailResponse = { + infoNotice: generateRandomInfoNotice(cartList), carts: cartList }; - addTransactionDetails(eventId, randomTransactionDetails); - return randomTransaction; + addNoticeDetails(eventId, randomNoticeDetails); + return randomNotice; }; -const generateUserTransactionData = () => { +const generateUserNoticeData = () => { for ( // eslint-disable-next-line functional/no-let let i = 0; i < ioDevServerConfig.features.payments.numberOfTransactions; i = i + 1 ) { - generateUserTransaction(faker.datatype.uuid(), i); + generateUserNotice(faker.datatype.uuid(), i); } }; // At server startup -generateUserTransactionData(); +generateUserNoticeData(); export default { - addUserTransaction, - getUserTransactions, - getTransactionDetails, - generateUserTransaction, - removeUserTransaction + addUserNotice, + getUserNotices, + getNoticeDetails, + generateUserNotice, + removeUserNotice }; diff --git a/src/features/payments/routers/transactions.ts b/src/features/payments/routers/notices.ts similarity index 72% rename from src/features/payments/routers/transactions.ts rename to src/features/payments/routers/notices.ts index ef860da7..1875beff 100644 --- a/src/features/payments/routers/transactions.ts +++ b/src/features/payments/routers/notices.ts @@ -1,14 +1,14 @@ import * as O from "fp-ts/lib/Option"; import { pipe } from "fp-ts/lib/function"; -import TransactionsDB from "../persistence/transactions"; +import NoticesDB from "../persistence/notices"; import { sendFileFromRootPath } from "../../../utils/file"; import { NoticeListWrapResponse } from "../../../../generated/definitions/pagopa/transactions/NoticeListWrapResponse"; -import { addTransactionHandler } from "./router"; +import { addNoticesHandler } from "./router"; const CONTINUATION_TOKEN_HEADER = "x-continuation-token"; -addTransactionHandler("get", "/paids", (req, res) => { +addNoticesHandler("get", "/paids", (req, res) => { const size = req.query.size ? Number(req.query.size) : 10; const offset = req.headers[CONTINUATION_TOKEN_HEADER] !== undefined && @@ -16,10 +16,10 @@ addTransactionHandler("get", "/paids", (req, res) => { ? Number(req.headers[CONTINUATION_TOKEN_HEADER]) : 0; const response: NoticeListWrapResponse = { - notices: TransactionsDB.getUserTransactions().slice(offset, offset + size) + notices: NoticesDB.getUserNotices().slice(offset, offset + size) }; const continuationToken = - TransactionsDB.getUserTransactions().length > offset + size + NoticesDB.getUserNotices().length > offset + size ? (offset + size).toString() : undefined; pipe( @@ -43,14 +43,14 @@ addTransactionHandler("get", "/paids", (req, res) => { ); }); -addTransactionHandler("get", "/paids/:transactionId", (req, res) => { +addNoticesHandler("get", "/paids/:eventId", (req, res) => { pipe( - req.params.transactionId, + req.params.eventId, O.fromNullable, O.fold( () => res.sendStatus(400), - transactionId => { - const transaction = TransactionsDB.getTransactionDetails(transactionId); + eventId => { + const transaction = NoticesDB.getNoticeDetails(eventId); return pipe( transaction, O.fold( @@ -63,14 +63,14 @@ addTransactionHandler("get", "/paids/:transactionId", (req, res) => { ); }); -addTransactionHandler("get", "/paids/:transactionId/pdf", (req, res) => { +addNoticesHandler("get", "/paids/:eventId/pdf", (req, res) => { pipe( - req.params.transactionId, + req.params.eventId, O.fromNullable, O.fold( () => res.sendStatus(400), - transactionId => { - const transaction = TransactionsDB.getTransactionDetails(transactionId); + eventId => { + const transaction = NoticesDB.getNoticeDetails(eventId); return pipe( transaction, O.fold( diff --git a/src/features/payments/routers/payment.ts b/src/features/payments/routers/payment.ts index 8d22fa3e..ec849fee 100644 --- a/src/features/payments/routers/payment.ts +++ b/src/features/payments/routers/payment.ts @@ -20,7 +20,7 @@ import { getTransactionInfoPayload } from "../payloads/transactions"; import WalletDB from "../persistence/userWallet"; -import TransactionsDB from "../persistence/transactions"; +import NoticesDB from "../persistence/notices"; import { WalletPaymentFailure, getStatusCodeForWalletFailure @@ -210,7 +210,7 @@ addPaymentHandler("post", "/mock-transaction", (req, res) => O.fold( () => res.sendStatus(404), () => { - TransactionsDB.generateUserTransaction(transactionId, 0); + NoticesDB.generateUserNotice(transactionId, 0); return res.status(200).json({ status: "ok" }); } ) diff --git a/src/features/payments/routers/router.ts b/src/features/payments/routers/router.ts index e6aad8c8..8165975f 100644 --- a/src/features/payments/routers/router.ts +++ b/src/features/payments/routers/router.ts @@ -5,7 +5,7 @@ export const walletRouter = Router(); export const PAYMENT_WALLET_PREFIX = "/io-payment-wallet/v1"; export const ECOMMERCE_PREFIX = "/ecommerce/io/v2"; -export const TRANSACTIONS_PREFIX = "/bizevents/notices-service-jwt/v1"; +export const NOTICES_PREFIX = "/bizevents/notices-service-jwt/v1"; export const PLATFORM_PREFIX = "/session-wallet/v1"; export const addPaymentWalletPrefix = (path: string) => @@ -14,8 +14,7 @@ export const addPaymentWalletPrefix = (path: string) => export const addECommercePrefix = (path: string) => `${ECOMMERCE_PREFIX}${path}`; -export const addTransactionPrefix = (path: string) => - `${TRANSACTIONS_PREFIX}${path}`; +export const addNoticesPrefix = (path: string) => `${NOTICES_PREFIX}${path}`; export const addPlatformPrefix = (path: string) => `${PLATFORM_PREFIX}${path}`; @@ -32,12 +31,11 @@ export const addPaymentHandler = ( handleRequest: (request: Request, response: Response) => void ) => addHandler(walletRouter, method, addECommercePrefix(path), handleRequest); -export const addTransactionHandler = ( +export const addNoticesHandler = ( method: SupportedMethod, path: string, handleRequest: (request: Request, response: Response) => void -) => - addHandler(walletRouter, method, addTransactionPrefix(path), handleRequest); +) => addHandler(walletRouter, method, addNoticesPrefix(path), handleRequest); export const addPlatformHandler = ( method: SupportedMethod, diff --git a/src/features/payments/utils/transactions.ts b/src/features/payments/utils/transactions.ts index 5769dcf3..c9608592 100644 --- a/src/features/payments/utils/transactions.ts +++ b/src/features/payments/utils/transactions.ts @@ -40,15 +40,15 @@ export const PAYMENT_METHODS_TRANSACTIONS_MOCK = [ } ]; -export const generateRandomInfoTransaction = ( +export const generateRandomInfoNotice = ( cartList: CartItem[], - transactionId?: string + eventId?: string ): InfoNotice => { const randomPaymentMethod = faker.helpers.arrayElement( PAYMENT_METHODS_TRANSACTIONS_MOCK ); return { - eventId: transactionId ?? ulid(), + eventId: eventId ?? ulid(), authCode: faker.random.alphaNumeric(6), rrn: faker.random.numeric(12), noticeDate: new Date().toISOString(), From c1e4bb96821658c23bf909c49c6b4752122587e4 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 17 Oct 2024 12:42:30 +0200 Subject: [PATCH 6/9] chore: Applied GH suggestions from @LeleDallas --- src/features/payments/routers/notices.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/features/payments/routers/notices.ts b/src/features/payments/routers/notices.ts index 1875beff..02ad348a 100644 --- a/src/features/payments/routers/notices.ts +++ b/src/features/payments/routers/notices.ts @@ -7,14 +7,13 @@ import { NoticeListWrapResponse } from "../../../../generated/definitions/pagopa import { addNoticesHandler } from "./router"; const CONTINUATION_TOKEN_HEADER = "x-continuation-token"; +const DEFAULT_SIZE = 10; addNoticesHandler("get", "/paids", (req, res) => { - const size = req.query.size ? Number(req.query.size) : 10; - const offset = - req.headers[CONTINUATION_TOKEN_HEADER] !== undefined && - req.headers[CONTINUATION_TOKEN_HEADER] !== "undefined" - ? Number(req.headers[CONTINUATION_TOKEN_HEADER]) - : 0; + const size = req.query.size ? Number(req.query.size) : DEFAULT_SIZE; + const offset = isNaN(Number(req.headers[CONTINUATION_TOKEN_HEADER])) + ? 0 + : Number(req.headers[CONTINUATION_TOKEN_HEADER]); const response: NoticeListWrapResponse = { notices: NoticesDB.getUserNotices().slice(offset, offset + size) }; From ac1bd610d638fd1e31c3947f160365737d8b8382 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 17 Oct 2024 12:48:30 +0200 Subject: [PATCH 7/9] fix: test ci --- src/features/payments/routers/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/payments/routers/index.ts b/src/features/payments/routers/index.ts index 35e032e9..fabc2ba4 100644 --- a/src/features/payments/routers/index.ts +++ b/src/features/payments/routers/index.ts @@ -1,6 +1,6 @@ import "./payment"; import "./wallets"; -import "./transactions"; +import "./notices"; import "./platform"; export { walletRouter } from "./router"; From 59a9b9b262153e1acb1f5495e46e97cbcc9bac77 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 17 Oct 2024 13:10:05 +0200 Subject: [PATCH 8/9] chore: Remove eslinter comment adding spread operator modifier --- src/features/payments/persistence/notices.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/features/payments/persistence/notices.ts b/src/features/payments/persistence/notices.ts index afaaf581..e73f1231 100644 --- a/src/features/payments/persistence/notices.ts +++ b/src/features/payments/persistence/notices.ts @@ -82,13 +82,14 @@ const generateUserNotice = ( .toString() }) ); - // eslint-disable-next-line functional/immutable-data - randomNotice.isCart = cartList.length > 1; - // eslint-disable-next-line functional/immutable-data - randomNotice.amount = cartList - .reduce((acc, item) => acc + Number(item.amount), 0) - .toString(); - addUserNotice(randomNotice); + const updatedNotice = { + ...randomNotice, + isCart: cartList.length > 1, + amount: cartList + .reduce((acc, item) => acc + Number(item.amount), 0) + .toString() + }; + addUserNotice(updatedNotice); const randomNoticeDetails: NoticeDetailResponse = { infoNotice: generateRandomInfoNotice(cartList), From dd831a9726d980cba6cce3f77e6187a72de689c7 Mon Sep 17 00:00:00 2001 From: Alessandro Izzo Date: Thu, 17 Oct 2024 13:14:02 +0200 Subject: [PATCH 9/9] chore: Removed eslint comment with the GH suggestion code --- src/features/payments/persistence/notices.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/features/payments/persistence/notices.ts b/src/features/payments/persistence/notices.ts index e73f1231..3f085470 100644 --- a/src/features/payments/persistence/notices.ts +++ b/src/features/payments/persistence/notices.ts @@ -100,12 +100,9 @@ const generateUserNotice = ( }; const generateUserNoticeData = () => { - for ( - // eslint-disable-next-line functional/no-let - let i = 0; - i < ioDevServerConfig.features.payments.numberOfTransactions; - i = i + 1 - ) { + for (const i of Array( + ioDevServerConfig.features.payments.numberOfTransactions + ).keys()) { generateUserNotice(faker.datatype.uuid(), i); } };