-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slett endepunkt skal fungere for sletting av vedlegg
- Loading branch information
Showing
1 changed file
with
25 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |