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

chore: [IOBP-927] Adapt new openAPI biz-events #423

Merged
merged 10 commits into from
Oct 17, 2024
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 18 additions & 16 deletions src/features/payments/persistence/transactions.ts
Original file line number Diff line number Diff line change
@@ -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"];
Hantex9 marked this conversation as resolved.
Show resolved Hide resolved

const userTransactions = new Map<TransactionId, TransactionListItem>();
const transactions = new Map<TransactionId, TransactionDetailResponse>();
const userTransactions = new Map<TransactionId, NoticeListItem>();
const transactions = new Map<TransactionId, NoticeDetailResponse>();

const getUserTransactions = () =>
Array.from(userTransactions.size > 0 ? userTransactions.values() : []);
Expand All @@ -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) => {
Expand All @@ -35,7 +35,7 @@ const removeUserTransaction = (transactionId: TransactionId) => {

const addTransactionDetails = (
transactionId: TransactionId,
transaction: TransactionDetailResponse
transaction: NoticeDetailResponse
) => {
transactions.set(transactionId, transaction);
};
Expand All @@ -45,20 +45,22 @@ const removeTransactionDetails = (transactionId: TransactionId) => {
};

const generateUserTransaction = (
transactionId: TransactionId,
eventId: TransactionId,
idx: number,
additionalTransactionInfo: Partial<TransactionInfo> = {}
) => {
const payeeTaxCode =
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
Expand Down Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion src/features/payments/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
17 changes: 7 additions & 10 deletions src/features/payments/routers/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,27 @@ 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";

addTransactionHandler("get", "/transactions", (req, res) => {
addTransactionHandler("get", "/paids", (req, res) => {
const size = req.query.size ? Number(req.query.size) : 10;
Hantex9 marked this conversation as resolved.
Show resolved Hide resolved
const offset =
req.headers[CONTINUATION_TOKEN_HEADER] !== undefined &&
req.headers[CONTINUATION_TOKEN_HEADER] !== "undefined"
? Number(req.headers[CONTINUATION_TOKEN_HEADER])
: 0;
Hantex9 marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand All @@ -46,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,
Expand All @@ -66,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,
Expand Down
10 changes: 5 additions & 5 deletions src/features/payments/utils/transactions.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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(),
Expand Down
Loading