Skip to content

Commit

Permalink
👽 Legger til api for krr
Browse files Browse the repository at this point in the history
Co-authored-by: Øivind Stensrud <oivind.stensrud@nav.no>
Co-authored-by: Tor Idland <tor.idland@nav.no>
  • Loading branch information
3 people committed Jan 3, 2024
1 parent 68e9fb8 commit 521a7f6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pages/api/oppslag/krr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { getAccessTokenFromRequest } from 'auth/accessToken';
import { beskyttetApi } from 'auth/beskyttetApi';
import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils';
import { isMock } from 'utils/environments';
import metrics from 'utils/metrics';

interface KontaktInformasjon {
epost?: string;
mobil?: string;
}

const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) => {
const accessToken = getAccessTokenFromRequest(req);
res.status(200).json(await getKrr(accessToken));
});

export const getKrr = async (accessToken?: string): Promise<KontaktInformasjon> => {
if (isMock()) return { epost: 'hello@pello.no', mobil: '12345678' };
const kontaktinformasjon = await tokenXApiProxy({
url: `${process.env.OPPSLAG_URL}/krr`,
prometheusPath: 'oppslag/krr',
method: 'GET',
audience: process.env.OPPSLAG_AUDIENCE!,
bearerToken: accessToken,
metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter,
metricsTimer: metrics.backendApiDurationHistogram,
logger: logger,
});

return kontaktinformasjon;
};

export default handler;

0 comments on commit 521a7f6

Please sign in to comment.