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(Bonus Pagamenti Digitali): [#175185419] Nesting WalletV2 inside Wallet #2310

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
68 changes: 35 additions & 33 deletions ts/types/pagopa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ export const Psp = repP(
);
export type Psp = t.TypeOf<typeof Psp>;

/** A refined WalletV2
* reasons:
* - createDate and updateDate are generated from spec as UTCISODateFromString instead of DateFromString
* - info is required
* - info is CardInfo and not PaymentMethodInfo (empty interface)
*/

// required attributes

const WalletV2O = t.partial({
updateDate: t.string,
createDate: DateFromString,
onboardingChannel: t.string,
favourite: t.boolean
});

// optional attributes
const WalletV2R = t.interface({
enableableFunctions: t.readonlyArray(t.string, "array of string"),
info: CardInfo,
idWallet: t.Integer,
pagoPA: t.boolean,
walletType: enumType<WalletTypeEnum>(WalletTypeEnum, "walletType")
});

export const PatchedWalletV2 = t.intersection(
[WalletV2R, WalletV2O],
"WalletV2"
);

export type PatchedWalletV2 = t.TypeOf<typeof PatchedWalletV2>;

/**
* A refined Wallet
*/
Expand All @@ -107,7 +139,9 @@ export const Wallet = repP(
t.union([Psp, t.undefined]),
"Wallet"
);
export type Wallet = t.TypeOf<typeof Wallet>;
// add v2 optional field. It may contain a PatchedWalletV2 object
const WalletV1V2 = t.intersection([Wallet, t.partial({ v2: PatchedWalletV2 })]);
export type Wallet = t.TypeOf<typeof WalletV1V2>;

/**
* A Wallet that has not being saved yet
Expand Down Expand Up @@ -292,38 +326,6 @@ export const PagoPAErrorResponse = t.type({

export type PagoPAErrorResponse = t.TypeOf<typeof PagoPAErrorResponse>;

/**
* reasons:
* - createDate and updateDate are generated from spec as UTCISODateFromString instead of DateFromString
* - info is required
* - info is CardInfo and not PaymentMethodInfo (empty interface)
*/

// required attributes

const WalletV2O = t.partial({
updateDate: t.string,
createDate: DateFromString,
onboardingChannel: t.string,
favourite: t.boolean
});

// optional attributes
const WalletV2R = t.interface({
enableableFunctions: t.readonlyArray(t.string, "array of string"),
info: CardInfo,
idWallet: t.Integer,
pagoPA: t.boolean,
walletType: enumType<WalletTypeEnum>(WalletTypeEnum, "walletType")
});

export const PatchedWalletV2 = t.intersection(
[WalletV2R, WalletV2O],
"WalletV2"
);

export type PatchedWalletV2 = t.TypeOf<typeof PatchedWalletV2>;

const WalletV2ListResponseR = t.interface({});

// optional attributes
Expand Down
3 changes: 2 additions & 1 deletion ts/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const convertWalletV2toWalletV1 = (
lastUsage: walletV2.updateDate ? new Date(walletV2.updateDate) : undefined,
isPspToIgnore: false,
registeredNexi: false,
saved: true
saved: true,
v2: walletV2
};
};