Skip to content

Commit

Permalink
✨ Legger til endepunkt for å hente alle søknader fra aap-oppslag
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrognes committed Jan 17, 2024
1 parent 5a862fb commit a89f52c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
20 changes: 5 additions & 15 deletions pages/api/soknader/soknader.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import { mockSøknader } from 'lib/mock/mockSoknad';
import {
logger,
isMock,
tokenXApiProxy,
beskyttetApi,
getAccessTokenFromRequest,
} from '@navikt/aap-felles-utils';
import { logger, isMock, tokenXApiProxy, beskyttetApi, getAccessTokenFromRequest } from '@navikt/aap-felles-utils';
import metrics from 'lib/metrics';

const handler = beskyttetApi(async (req, res) => {
const accessToken = getAccessTokenFromRequest(req);
const params = {};
const søknader = await getSøknader(params, accessToken);
const søknader = await getSøknader(accessToken);
res.status(200).json(søknader);
});

export const getSøknader = async (params: Record<string, string>, accessToken?: string) => {
export const getSøknader = async (accessToken?: string) => {
if (isMock()) return mockSøknader;
const urlParams = Object.entries(params)
.map(([key, value]) => `${key}=${value}`)
.join('&');
const søknader = await tokenXApiProxy({
url: `${process.env.SOKNAD_API_URL}/oppslag/soeknader${urlParams ? '?' + urlParams : ''}`,
url: `${process.env.OPPSLAG_API_URL}/innsending/søknader`,
prometheusPath: '/oppslag/soeknader',
method: 'GET',
audience: process.env.SOKNAD_API_AUDIENCE ?? '',
audience: process.env.OPPSLAG_AUDIENCE ?? '',
bearerToken: accessToken,
logger: logger,
metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter,
Expand Down
5 changes: 2 additions & 3 deletions pages/ettersendelse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReadMore, Label, BodyShort, Button, Heading, Link } from '@navikt/ds-react';
import { BodyShort, Button, Heading, Label, Link, ReadMore } from '@navikt/ds-react';
import { PageHeader } from 'components/PageHeader';
import { Section } from 'components/Section/Section';
import { beskyttetSide, getAccessToken } from '@navikt/aap-felles-utils';
Expand Down Expand Up @@ -101,8 +101,7 @@ export const getServerSideProps = beskyttetSide(async (ctx: NextPageContext): Pr
path: '/ettersendelse',
});
const bearerToken = getAccessToken(ctx);
const params = { page: '0', size: '1', sort: 'created,desc' };
const søknader = await getSøknader(params, bearerToken);
const søknader = await getSøknader(bearerToken);
stopTimer();

if (søknader.length > 0) {
Expand Down
3 changes: 1 addition & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ const Index = ({ søknader }: { søknader: Søknad[] }) => {
export const getServerSideProps = beskyttetSide(async (ctx: NextPageContext): Promise<GetServerSidePropsResult<{}>> => {
const stopTimer = metrics.getServersidePropsDurationHistogram.startTimer({ path: '/' });
const bearerToken = getAccessToken(ctx);
const params = { page: '0', size: '1', sort: 'created,desc' };

const [søknader] = await Promise.all([getSøknader(params, bearerToken)]);
const søknader = await getSøknader(bearerToken);

stopTimer();

Expand Down
3 changes: 1 addition & 2 deletions pages/soknader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ const Søknader = ({ søknader }: PageProps) => {
export const getServerSideProps = beskyttetSide(async (ctx: NextPageContext): Promise<GetServerSidePropsResult<{}>> => {
const stopTimer = metrics.getServersidePropsDurationHistogram.startTimer({ path: '/soknader' });
const bearerToken = getAccessToken(ctx);
const params = { page: '0', size: '200', sort: 'created,desc' };
const søknader = await getSøknader(params, bearerToken);
const søknader = await getSøknader(bearerToken);

logger.info(`søknader: ${JSON.stringify(søknader)}`);

Expand Down

0 comments on commit a89f52c

Please sign in to comment.