Skip to content

Commit

Permalink
Merge branch 'main' into MIJN-9631-3-fe-en-be-realiseren-contactmomen…
Browse files Browse the repository at this point in the history
…t-uit-sf
  • Loading branch information
timvanoostrom authored Jan 9, 2025
2 parents adefaed + 59631c3 commit 42cd908
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 140 deletions.
6 changes: 2 additions & 4 deletions src/client/pages/VergunningenV2/VergunningDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Grid } from '@amsterdam/design-system-react';
import { useParams } from 'react-router-dom';

import {
VergunningDocument,
VergunningFrontendV2,
} from '../../../server/services/vergunningen-v2/config-and-types';
import { VergunningFrontendV2 } from '../../../server/services/vergunningen-v2/config-and-types';
import { isError, isLoading } from '../../../universal/helpers/api';
import { CaseTypeV2 } from '../../../universal/types/vergunningen';
import { ThemaIcon } from '../../components';
Expand All @@ -17,6 +14,7 @@ import { AanbiedenDienstenContent } from './detail-page-content/AanbiedenDienste
import { GPPContent } from './detail-page-content/GPP';
import { WVOSContent } from './detail-page-content/WVOS';
import { LinkProps } from '../../../universal/types';
import { VergunningDocument } from '../../../server/services';

interface DetailPageContentProps {
vergunning: VergunningFrontendV2;
Expand Down
105 changes: 50 additions & 55 deletions src/server/services/decos/decos-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import uid from 'uid-safe';
import {
fetchDecosDocumentList,
fetchDecosZaken,
fetchDecosWorkflowDate,
fetchDecosWorkflowDates,
fetchDecosZakenFromSource,
forTesting,
} from './decos-service';
Expand Down Expand Up @@ -198,15 +198,13 @@ describe('decos-service', () => {
.get(/\/decos\/items\/123-abc-000\/workflowlinkinstances/)
.reply(200);

const responseData = await fetchDecosWorkflowDate(
reqID,
'zaak-id-1',
'zaak - behandelen'
);
const responseData = await fetchDecosWorkflowDates(reqID, 'zaak-id-1', [
'zaak - behandelen',
]);

expect(responseData).toMatchInlineSnapshot(`
{
"content": null,
"content": {},
"status": "OK",
}
`);
Expand All @@ -221,18 +219,14 @@ describe('decos-service', () => {
.get(/\/decos\/items\/123-abc-000\/workflowlinkinstances/)
.reply(200, workflowInstance);

const responseData = await fetchDecosWorkflowDate(
reqID,
'zaak-id-1',
'Zaak - behandelen'
);
const responseData = await fetchDecosWorkflowDates(reqID, 'zaak-id-1', [
'Zaak - behandelen',
]);

expect(responseData).toMatchInlineSnapshot(`
{
"content": "2021-09-13T17:09:00",
"status": "OK",
}
`);
expect(responseData).toMatchObject({
content: { 'Zaak - behandelen': '2021-09-13T17:09:00' },
status: 'OK',
});
});

test('Without date', async () => {
Expand All @@ -250,18 +244,14 @@ describe('decos-service', () => {
.get(/\/decos\/items\/123-abc-000\/workflowlinkinstances/)
.reply(200, workflowInstance2);

const responseData = await fetchDecosWorkflowDate(
reqID,
'zaak-id-1',
'Zaak - behandelen'
);
const responseData = await fetchDecosWorkflowDates(reqID, 'zaak-id-1', [
'Zaak - behandelen',
]);

expect(responseData).toMatchInlineSnapshot(`
{
"content": null,
"status": "OK",
}
`);
expect(responseData).toMatchObject({
content: { 'Zaak - behandelen': null },
status: 'OK',
});
});
});

Expand Down Expand Up @@ -572,27 +562,29 @@ describe('decos-service', () => {
delete (fields as Partial<typeof fields>).date1;

const date = forTesting.transformDecosWorkflowDateResponse(
'Zaak - behandelen',
['Zaak - behandelen'],
workflowInstance2
);

expect(date).toBe(null);
expect(date).toMatchObject({ 'Zaak - behandelen': null });
});

test('Has date', () => {
const date = forTesting.transformDecosWorkflowDateResponse(
'Zaak - behandelen',
['Zaak - behandelen'],
workflowInstance
);
expect(date).toBe(workflowInstance.content[0].fields.date1);
expect(date).toMatchObject({
'Zaak - behandelen': workflowInstance.content[0].fields.date1,
});
});

test('Wrong step title', () => {
const date = forTesting.transformDecosWorkflowDateResponse(
'Zaak - in behandeling',
['Zaak - in behandeling'],
workflowInstance
);
expect(date).toBe(null);
expect(date).toMatchObject({ 'Zaak - in behandeling': null });
});
});

Expand Down Expand Up @@ -635,26 +627,29 @@ describe('decos-service', () => {
zakenSource.content[0]
);

expect(transformed).toMatchInlineSnapshot(`
{
"caseType": "Werk en vervoer op straat",
"dateDecision": null,
"dateEnd": "2023-12-14T00:00:00",
"dateInBehandeling": "2024-05-04",
"dateRequest": "2023-11-06T00:00:00",
"dateStart": "2023-11-27T00:00:00",
"decision": null,
"id": "Z-23-2230424",
"identifier": "Z/23/2230424",
"kentekens": "95GHZ4",
"key": "084239C942C647F79F1C2B5CCF8DC5DA",
"location": null,
"processed": false,
"status": "In behandeling",
"title": "Werkzaamheden en vervoer op straat (95GHZ4)",
"werkzaamheden": [],
}
`);
expect(transformed).toMatchObject({
caseType: 'Werk en vervoer op straat',
dateDecision: null,
dateEnd: '2023-12-14T00:00:00',
dateRequest: '2023-11-06T00:00:00',
dateStart: '2023-11-27T00:00:00',
decision: null,
id: 'Z-23-2230424',
identifier: 'Z/23/2230424',
kentekens: '95GHZ4',
key: '084239C942C647F79F1C2B5CCF8DC5DA',
location: null,
processed: false,
status: 'In behandeling',
statusDates: [
{
status: 'In behandeling',
datePublished: '2024-05-04',
},
],
title: 'Werkzaamheden en vervoer op straat (95GHZ4)',
werkzaamheden: [],
});
});

test('Excluded', async () => {
Expand Down
83 changes: 55 additions & 28 deletions src/server/services/decos/decos-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DecosZakenResponse,
SELECT_FIELDS_META,
SELECT_FIELDS_TRANSFORM_BASE,
DecosWorkflowResponse,
} from './decos-types';
import {
getDecosZaakTypeFromSource,
Expand All @@ -27,6 +28,7 @@ import {
} from './helpers';
import {
ApiErrorResponse,
ApiResponse,
ApiSuccessResponse,
apiSuccessResult,
getSettledResult,
Expand Down Expand Up @@ -155,8 +157,8 @@ async function transformDecosZaakResponse<
}

// Reference to decos workflow service for use in transformers
const fetchWorkflowDate = (stepTitle: string) => {
return fetchDecosWorkflowDate(requestID, decosZaakSource.key, stepTitle);
const fetchWorkflowDates = (stepTitles: string[]) => {
return fetchDecosWorkflowDates(requestID, decosZaakSource.key, stepTitles);
};

// Iterates over the desired data fields (key=>value pairs) and transforms values if necessary.
Expand All @@ -178,7 +180,7 @@ async function transformDecosZaakResponse<
typeof fieldTransformer.transform === 'function'
? fieldTransformer.transform(value, {
decosZaakTransformer,
fetchDecosWorkflowDate: fetchWorkflowDate,
fetchDecosWorkflowDates: fetchWorkflowDates,
})
: value;
} catch (err) {
Expand All @@ -200,17 +202,23 @@ async function transformDecosZaakResponse<
'unknown-decoszaak-id',
key: decosZaakSource.key,
title: decosZaakTransformer.title,
dateInBehandeling: null, // Serves as placeholder, value for this property will be added async below.
statusDates: [], // Serves as placeholder, values for this property will be added async below.
...transformedFields,
};

// Try to fetch and assign a specific date on which the zaak was "In behandeling"
if (decosZaakTransformer.dateInBehandelingWorkflowStepTitle) {
const { content: dateInBehandeling } = await fetchWorkflowDate(
decosZaakTransformer.dateInBehandelingWorkflowStepTitle
if (decosZaakTransformer.fetchWorkflowStatusDatesFor) {
const stepTitles = decosZaakTransformer.fetchWorkflowStatusDatesFor.map(
({ stepTitle }) => stepTitle
);
if (dateInBehandeling) {
decosZaak.dateInBehandeling = dateInBehandeling;
const workFlowDates = await fetchWorkflowDates(stepTitles);
if (workFlowDates.status === 'OK') {
decosZaak.statusDates =
decosZaakTransformer.fetchWorkflowStatusDatesFor.map(
({ status, stepTitle }) => ({
status,
datePublished: workFlowDates.content[stepTitle],
})
);
}
}

Expand All @@ -225,7 +233,7 @@ async function transformDecosZaakResponse<
decosZaak,
decosZaakSource,
{
fetchDecosWorkflowDate: fetchWorkflowDate,
fetchDecosWorkflowDates: fetchWorkflowDates,
decosZaakTransformer,
}
);
Expand Down Expand Up @@ -412,23 +420,34 @@ function transformDecosWorkflowKeysResponse(workflowsResponseData: {
}

function transformDecosWorkflowDateResponse(
stepTitle: DecosWorkflowStepTitle,
singleWorkflowResponseData: {
content: Array<{ fields: { text7: string; date1?: string } }>;
}
) {
return (
singleWorkflowResponseData.content?.find((workflowStep) => {
return workflowStep.fields.text7 === stepTitle;
})?.fields.date1 ?? null
stepTitles: DecosWorkflowStepTitle[],
singleWorkflowResponseData: DecosWorkflowResponse
): { [key: DecosWorkflowStepTitle]: string | null } {
const responseStepTitleDates = singleWorkflowResponseData.content
.filter((workflowStep) => workflowStep.fields.text7 != null)
.reduce(
(acc, workflowStep) => ({
...acc,
[workflowStep.fields.text7]: workflowStep.fields.date1 ?? null,
}),
{} as Record<string, string | null>
);

const stepTitleToDate = stepTitles.reduce(
(acc, stepTitle) => ({
...acc,
[stepTitle]: responseStepTitleDates[stepTitle] ?? null,
}),
{} as Record<DecosWorkflowStepTitle, string | null>
);
return stepTitleToDate;
}

export async function fetchDecosWorkflowDate(
export async function fetchDecosWorkflowDates(
requestID: RequestID,
zaakID: DecosZaakBase['key'],
stepTitle: DecosWorkflowStepTitle
) {
stepTitles: DecosWorkflowStepTitle[]
): Promise<ApiResponse<Record<string, DecosWorkflowStepDate | null>>> {
const apiConfigWorkflows = getApiConfig('DECOS_API', {
formatUrl: (config) => {
return `${config.url}/items/${zaakID}/workflows`;
Expand All @@ -442,18 +461,26 @@ export async function fetchDecosWorkflowDate(
);

if (!latestWorkflowKey) {
return apiSuccessResult(null);
return apiSuccessResult({});
}

const urlParams = new URLSearchParams({
top: '50',
properties: 'false',
fetchParents: 'false',
select: ['mark', 'date1', 'date2', 'text7'].join(','),
filter: stepTitles.map((stepTitle) => `text7 eq ${stepTitle}`).join(' or '),
});

const apiConfigSingleWorkflow = getApiConfig('DECOS_API', {
formatUrl: (config) => {
return `${config.url}/items/${latestWorkflowKey}/workflowlinkinstances?properties=false&fetchParents=false&select=mark,date1,date2,text7,sequence&orderBy=sequence&filter=text7 eq '${stepTitle}'`;
return `${config.url}/items/${latestWorkflowKey}/workflowlinkinstances?'${urlParams}'`;
},
transformResponse: (responseData) =>
transformDecosWorkflowDateResponse(stepTitle, responseData),
transformResponse: (responseData: DecosWorkflowResponse) =>
transformDecosWorkflowDateResponse(stepTitles, responseData),
});

return requestData<DecosWorkflowStepDate>(apiConfigSingleWorkflow, requestID);
return requestData(apiConfigSingleWorkflow, requestID);
}

async function fetchIsPdfDocument(
Expand Down
Loading

0 comments on commit 42cd908

Please sign in to comment.