Skip to content

Commit

Permalink
⚗️ Vedlegg sendes som kommaseparert liste av uuid i header 'vedlegg'
Browse files Browse the repository at this point in the history
Co-authored-by: Øivind Stensrud <[email protected]>
Co-authored-by: Thomas Rognes <[email protected]>
  • Loading branch information
3 people committed May 31, 2024
1 parent e77c733 commit a2321a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fetch from 'cross-fetch';

export const fetchPOST = async (url: string, payload: object) => {
export const fetchPOST = async (url: string, payload: object, options?: RequestInit) => {
const headers = {
'Content-Type': 'application/json',
...options?.headers,
};
try {
const res = await fetch(url, {
Expand Down
11 changes: 6 additions & 5 deletions hooks/useDebounceLagreSoknad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback } from 'react';
import { formatDateTime } from 'utils/date';
import { setSistLagret, useAppStateContext } from 'context/appStateContext';
import { SoknadContextState } from 'context/soknadcontext/soknadContext';
import { søknadVedleggStateTilFilArray } from 'utils/vedlegg';
import { søknadVedleggStateTilFilIdString } from 'utils/vedlegg';

export function useDebounceLagreSoknad<SoknadStateType>() {
const { appStateDispatch } = useAppStateContext();
Expand Down Expand Up @@ -35,10 +35,11 @@ export function useDebounceLagreSoknad<SoknadStateType>() {
}
export async function mellomLagreSøknad(contextState: SoknadContextState) {
if (contextState.søknad) {
const vedlegg = søknadVedleggStateTilFilArray(contextState.søknad);
return await fetchPOST(`/aap/soknad/api/mellomlagring/lagre`, {
soknad: contextState,
vedlegg,
const vedleggString = søknadVedleggStateTilFilIdString(contextState.søknad);
return await fetchPOST(`/aap/soknad/api/mellomlagring/lagre`, contextState, {
headers: {
vedlegg: vedleggString,
},
});
}
}
3 changes: 1 addition & 2 deletions pages/api/mellomlagring/les.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const hentMellomlagring = async (
}
if (isMock()) {
const result = await lesCache();
const parsedResult = result ? JSON.parse(result) : {};
return parsedResult?.soknad || {};
return result ? JSON.parse(result) : {};
}
try {
const mellomlagretSøknad = await simpleTokenXProxy<SoknadContextState | string>({
Expand Down
6 changes: 6 additions & 0 deletions utils/vedlegg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const søknadVedleggStateTilFilArray = (søknad: Soknad) => {
.flat();
return filer;
};

export const søknadVedleggStateTilFilIdString = (søknad: Soknad) => {
return søknadVedleggStateTilFilArray(søknad)
.map((fil) => fil.id)
.join(',');
};
function mapVedleggTypeTilVedleggTekst(vedleggType: AttachmentType): string {
switch (vedleggType) {
case 'LØNN_OG_ANDRE_GODER':
Expand Down

0 comments on commit a2321a5

Please sign in to comment.