Skip to content

Commit

Permalink
Merge pull request #3366 from navikt/bugfix/get-query-identer
Browse files Browse the repository at this point in the history
Delt opp lange querys for identer
  • Loading branch information
betsytraran authored Jan 2, 2024
2 parents f29d3c9 + ad0cfd9 commit e21446a
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@ import Request from '@/service/services/Request'

const getPdlUrl = () => '/testnav-pdl-forvalter/api/v1'

const sliceIdentListe = (identListe: string[]) => {
const maxAntall = 150
if (identListe.length <= maxAntall) return [identListe]
const identer = []
for (let i = 0; i < identListe.length; i += maxAntall) {
identer.push(identListe.slice(i, i + maxAntall))
}
return identer
}

export default {
getPersoner(identListe: string[]) {
if (!identListe) {
return
}
const endpoint = `${getPdlUrl()}/personer?identer=${identListe}`
return Request.get(endpoint)
const identerDelt = sliceIdentListe(identListe)
const promises = identerDelt.map((identer) => {
const endpoint = `${getPdlUrl()}/personer?identer=${identer}`
return Request.get(endpoint)
})
return Promise.all(promises).then((responses) => {
const data = responses.map((response: any) => response?.data).flat()
return { data }
})
},
soekPersoner(fragment: string) {
if (!fragment || fragment.length > 11) {
Expand Down

0 comments on commit e21446a

Please sign in to comment.