From 87d528ed5c6685e5eb59549e0ff13bd881849c88 Mon Sep 17 00:00:00 2001 From: Marnix Dessing Date: Mon, 31 Oct 2022 10:11:20 +0100 Subject: [PATCH] feat: disable issuing after callback --- src/app/callback/callbackRequestHandler.ts | 2 +- src/app/issue/issueRequestHandler.ts | 27 ++++++++++++++-------- test/__snapshots__/main.test.ts.snap | 4 ++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/callback/callbackRequestHandler.ts b/src/app/callback/callbackRequestHandler.ts index 3f310803..2be75564 100644 --- a/src/app/callback/callbackRequestHandler.ts +++ b/src/app/callback/callbackRequestHandler.ts @@ -25,7 +25,7 @@ export async function callbackRequestHandler(params: any, dynamoDBClient: Dynamo async function handleLoggedinRequest(session: Session, params: any, dynamoDBClient: DynamoDBClient) { if (session.getValue('issued', 'BOOL')) { - return; + return Response.json({ message: 'Callback already performed' }); } const bsn = session.getValue('bsn', 'S'); diff --git a/src/app/issue/issueRequestHandler.ts b/src/app/issue/issueRequestHandler.ts index d30f895a..cd06228a 100644 --- a/src/app/issue/issueRequestHandler.ts +++ b/src/app/issue/issueRequestHandler.ts @@ -28,15 +28,24 @@ export async function issueRequestHandler(cookies: string, brpClient: ApiClient, * @returns */ async function handleLoggedinRequest(session: Session, brpClient: ApiClient, irmaApi: IrmaApi) { - // BRP request - const bsn = session.getValue('bsn'); - const brpApi = new BrpApi(brpClient); - const brpData = await brpApi.getBrpData(bsn); - const naam = brpData?.Persoon?.Persoonsgegevens?.Naam ? brpData.Persoon.Persoonsgegevens.Naam : 'Onbekende gebruiker'; - let error = undefined; - if (brpData.error) { - error = 'Het ophalen van uw persoonsgegevens is mis gegaan.'; + + // If issuing already is completed + if (session.getValue('issued', 'BOOL')) { + error = 'Om uw gegevens nog een keer in te laden dient u eerst uit te loggen'; + } + + // BRP request + let naam = 'Onbekende gebruiker'; + let brpData = undefined; + if (!error) { + const bsn = session.getValue('bsn'); + const brpApi = new BrpApi(brpClient); + brpData = await brpApi.getBrpData(bsn); + naam = brpData?.Persoon?.Persoonsgegevens?.Naam ?? naam; + if (brpData.error) { + error = 'Het ophalen van uw persoonsgegevens is mis gegaan.'; + } } // Start IRMA session @@ -89,4 +98,4 @@ async function storeIssueEventInSession(brpData: any, session: Session) { } catch (err) { console.log('Could not add issue statistics to session', err); } -} \ No newline at end of file +} diff --git a/test/__snapshots__/main.test.ts.snap b/test/__snapshots__/main.test.ts.snap index 81f0529a..fd17418a 100644 --- a/test/__snapshots__/main.test.ts.snap +++ b/test/__snapshots__/main.test.ts.snap @@ -403,7 +403,7 @@ Object { }, \\"build\\": { \\"commands\\": [ - \\"cdk-assets --path \\\\\\"assembly-test-irma-issue-api/testirmaissueapiapistack38F434B4.assets.json\\\\\\" --verbose publish \\\\\\"d95c86349209b9103626f5c71a5cb54416afd045c8d8e113c106bf4ec74e8635:test-eu-west-1\\\\\\"\\" + \\"cdk-assets --path \\\\\\"assembly-test-irma-issue-api/testirmaissueapiapistack38F434B4.assets.json\\\\\\" --verbose publish \\\\\\"a2550986443c4990d05aca3073ffa2b0132f92d2feb9ca19e33c4135d6b96d11:test-eu-west-1\\\\\\"\\" ] } } @@ -462,7 +462,7 @@ Object { }, \\"build\\": { \\"commands\\": [ - \\"cdk-assets --path \\\\\\"assembly-test-irma-issue-api/testirmaissueapiapistack38F434B4.assets.json\\\\\\" --verbose publish \\\\\\"e7bf09370aceedadd3963a278963b4625a205e0edfbe43be05e85214689b6a3b:test-eu-west-1\\\\\\"\\" + \\"cdk-assets --path \\\\\\"assembly-test-irma-issue-api/testirmaissueapiapistack38F434B4.assets.json\\\\\\" --verbose publish \\\\\\"db267d74bb001d3b465a80f07db92bf2ed0f7fd8066d903658b8b602762bb837:test-eu-west-1\\\\\\"\\" ] } }