-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOBP-927] Adapt new openAPI biz-events (#423)
* chore: Adapt new openAPI biz-events * chore: Changed route * chore: edit baseurl * chore: edit api path from transactions to paids * chore: Replaced `transaction` occurrences with `notice` * chore: Applied GH suggestions from @LeleDallas * fix: test ci * chore: Remove eslinter comment adding spread operator modifier * chore: Removed eslint comment with the GH suggestion code
- Loading branch information
Showing
8 changed files
with
155 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { faker } from "@faker-js/faker"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
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 { generateRandomInfoNotice } from "../utils/transactions"; | ||
import { ioDevServerConfig } from "../../../config"; | ||
|
||
const mockedTaxCodes = ["1199250158", "13756881002", "262700362", "31500945"]; | ||
|
||
type EventId = NoticeListItem["eventId"]; | ||
|
||
const userNotices = new Map<EventId, NoticeListItem>(); | ||
const notices = new Map<EventId, NoticeDetailResponse>(); | ||
|
||
const getUserNotices = () => | ||
Array.from(userNotices.size > 0 ? userNotices.values() : []); | ||
|
||
const getNoticeDetails = (eventId: EventId) => | ||
pipe( | ||
notices, | ||
O.fromNullable, | ||
O.chain(notices => O.fromNullable(notices.get(eventId))) | ||
); | ||
|
||
const addUserNotice = (transaction: NoticeListItem) => { | ||
userNotices.set(transaction.eventId, transaction); | ||
}; | ||
|
||
const removeUserNotice = (eventId: EventId) => { | ||
userNotices.delete(eventId); | ||
removeNoticeDetails(eventId); | ||
}; | ||
|
||
const addNoticeDetails = (eventId: EventId, notice: NoticeDetailResponse) => { | ||
notices.set(eventId, notice); | ||
}; | ||
|
||
const removeNoticeDetails = (eventId: EventId) => { | ||
notices.delete(eventId); | ||
}; | ||
|
||
const generateUserNotice = ( | ||
eventId: EventId, | ||
idx: number, | ||
additionalTransactionInfo: Partial<TransactionInfo> = {} | ||
) => { | ||
const payeeTaxCode = | ||
mockedTaxCodes[ | ||
faker.datatype.number({ min: 0, max: mockedTaxCodes.length - 1 }) | ||
]; | ||
const randomNotice: NoticeListItem = { | ||
eventId, | ||
payeeName: faker.company.name(), | ||
payeeTaxCode, | ||
isDebtor: false, | ||
isPayer: true, | ||
amount: additionalTransactionInfo.payments?.[0]?.amount.toString() || "", | ||
noticeDate: new Date( | ||
new Date().setDate(new Date().getDate() - 2 * idx) | ||
).toISOString(), | ||
isCart: false | ||
}; | ||
|
||
const cartList = Array.from( | ||
{ length: faker.datatype.number({ min: 1, max: 2 }) }, | ||
() => ({ | ||
subject: faker.lorem.sentence(faker.datatype.number({ min: 2, max: 4 })), | ||
amount: faker.finance.amount(1, 1000), | ||
payee: { | ||
name: randomNotice.payeeName, | ||
taxCode: randomNotice.payeeTaxCode | ||
}, | ||
debtor: { | ||
name: faker.name.fullName(), | ||
taxCode: faker.random.alphaNumeric(16).toUpperCase() | ||
}, | ||
refNumberType: "IBAN", | ||
refNumberValue: faker.datatype | ||
.number({ min: 100000000000, max: 999999999999 }) | ||
.toString() | ||
}) | ||
); | ||
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), | ||
carts: cartList | ||
}; | ||
addNoticeDetails(eventId, randomNoticeDetails); | ||
return randomNotice; | ||
}; | ||
|
||
const generateUserNoticeData = () => { | ||
for (const i of Array( | ||
ioDevServerConfig.features.payments.numberOfTransactions | ||
).keys()) { | ||
generateUserNotice(faker.datatype.uuid(), i); | ||
} | ||
}; | ||
|
||
// At server startup | ||
generateUserNoticeData(); | ||
|
||
export default { | ||
addUserNotice, | ||
getUserNotices, | ||
getNoticeDetails, | ||
generateUserNotice, | ||
removeUserNotice | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import "./payment"; | ||
import "./wallets"; | ||
import "./transactions"; | ||
import "./notices"; | ||
import "./platform"; | ||
|
||
export { walletRouter } from "./router"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.