Skip to content

Commit

Permalink
Refactor getBrukerStatistikk
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehansen2 committed Apr 3, 2024
1 parent 60866f5 commit 4a68934
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { useAmplitudeInstance } from '@navikt/sif-common-amplitude';
import { useEffectOnce } from '@navikt/sif-common-hooks';
import { PleietrengendeMedSak } from '../server/api-models/PleietrengendeMedSakSchema';
import { InnsendtSøknad } from '../types/Søknad';
import { getBrukerprofil } from '../utils/brukerprofilUtils';
import { getBrukerStatistikk } from '../utils/brukerStatistikkUtils';

export const useLogBrukerprofil = (
export const useLogBrukerstatistikk = (
søknader: InnsendtSøknad[],
saker: PleietrengendeMedSak[],
saksbehandlingstidUker: number | undefined,
) => {
const { logInfo } = useAmplitudeInstance();

useEffectOnce(() => {
const brukerprofil = getBrukerprofil(søknader, saker, saksbehandlingstidUker);
const statistikk = getBrukerStatistikk(søknader, saker, saksbehandlingstidUker);
logInfo({
type: 'brukerprofil',
...brukerprofil,
...statistikk,
});
});
};
4 changes: 2 additions & 2 deletions apps/dine-pleiepenger/src/pages/api/innsynsdata.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getXRequestId } from '../../utils/apiUtils';
import { Feature } from '../../utils/features';
import { sortInnsendtSøknadEtterOpprettetDato } from '../../utils/innsendtSøknadUtils';
import { fetchAppStatus } from './appStatus.api';
import { getBrukerprofil } from '../../utils/brukerprofilUtils';
import { getBrukerStatistikk } from '../../utils/brukerStatistikkUtils';

async function handler(req: NextApiRequest, res: NextApiResponse) {
const childLogger = createChildLogger(getXRequestId(req));
Expand Down Expand Up @@ -51,7 +51,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
? saksbehandlingstidReq.value.saksbehandlingstidUker
: undefined;

childLogger.info(getBrukerprofil(søknader, saker, saksbehandlingstidUker), `Hentet innsynsdata`);
childLogger.info(getBrukerStatistikk(søknader, saker, saksbehandlingstidUker), `Hentet innsynsdata`);

const innsynsdata: Innsynsdata = {
appStatus: appStatus.status === 'fulfilled' ? appStatus.value : undefined,
Expand Down
4 changes: 2 additions & 2 deletions apps/dine-pleiepenger/src/pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import DefaultPageLayout from '../components/page-layout/default-page-layout/Def
import Snarveier from '../components/snarveier/Snarveier';
import Saksbehandlingstid from '../components/saksbehandlingstid/Saksbehandlingstid';
import { useInnsynsdataContext } from '../hooks/useInnsynsdataContext';
import { useLogBrukerprofil } from '../hooks/useLogBrukerprofil';
import { useLogBrukerstatistikk } from '../hooks/useLogBrukerstatistikk';
import { useMessages } from '../i18n';
import { PleietrengendeMedSak } from '../server/api-models/PleietrengendeMedSakSchema';
import { InnsendtSøknad, InnsendtSøknadstype } from '../types/Søknad';
Expand All @@ -35,7 +35,7 @@ function DinePleiepengerPage(): ReactElement {
innsynsdata: { innsendteSøknader, saker, saksbehandlingstidUker },
} = useInnsynsdataContext();

useLogBrukerprofil(innsendteSøknader, saker, saksbehandlingstidUker);
useLogBrukerstatistikk(innsendteSøknader, saker, saksbehandlingstidUker);

const { text } = useMessages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import { PleietrengendeMedSak } from '../server/api-models/PleietrengendeMedSakS
import { getEndringsmeldinger, getEttersendelser, getPleiepengesøknader } from './innsendtSøknadUtils';
import { InnsendtSøknad } from '../types/Søknad';

export const getBrukerprofil = (
type BrukerStatistikk = {
antallSøknader: number;
antallEttersendelser: number;
antallEndringsmeldinger: number;
sisteSøknad: Date | undefined;
sisteEndring: Date | undefined;
sisteEttersendelse: Date | undefined;
antallSaker: number;
harSaksbehandlingstid: boolean;
perioder: string[];
};

export const getBrukerStatistikk = (
søknader: InnsendtSøknad[],
saker: PleietrengendeMedSak[],
saksbehandlingstidUker: number | undefined,
) => {
): BrukerStatistikk => {
const ppSøknader = getPleiepengesøknader(søknader);
const ppEndringer = getEndringsmeldinger(søknader);
const ppEttersendelser = getEttersendelser(søknader);
Expand Down

0 comments on commit 4a68934

Please sign in to comment.