Skip to content

Commit

Permalink
Slett endepunkt skal fungere for sletting av vedlegg
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbjoern committed Dec 15, 2023
1 parent 04f5e85 commit c313549
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pages/api/innsending/vedlegg/slett.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import { getStringFromPossiblyArrayQuery } from '@navikt/aap-felles-utils-client';
import { beskyttetApi, getAccessTokenFromRequest, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { beskyttetApi, getAccessTokenFromRequest, getTokenX } from '@navikt/aap-felles-utils';
import { proxyApiRouteRequest } from '@navikt/next-api-proxy';

const handler = beskyttetApi(async (req, res) => {
const uuid = getStringFromPossiblyArrayQuery(req.query.uuid);
if (!uuid) {
res.status(400).json({ error: 'uuid må være en string' });
}
const accessToken = getAccessTokenFromRequest(req);
return await tokenXApiProxy({
url: `${process.env.INNSENDING_URL}/mellomlagring/fil/${uuid}`,
method: 'DELETE',
prometheusPath: '/mellomlagring/fil',
req,
audience: process.env.INNSENDING_AUDIENCE!,
bearerToken: accessToken,
noResponse: true,

const accessToken = getAccessTokenFromRequest(req)?.substring('Bearer '.length)!;
let tokenxToken;
try {
tokenxToken = await getTokenX(accessToken, process.env.INNSENDING_AUDIENCE!);
} catch (err: any) {
console.log('getTokenXError', err);
}
return await proxyApiRouteRequest({
hostname: 'innsending',
path: `/mellomlagring/fil/${uuid}`,
req: req,
/* @ts-ignore: TODO */
res: res,
bearerToken: tokenxToken,
https: false,
});
});

export const config = {
api: {
bodyParser: false,
externalResolver: true,
},
};

export default handler;

0 comments on commit c313549

Please sign in to comment.