Skip to content

Commit

Permalink
Delt opp lange querys for identer
Browse files Browse the repository at this point in the history
  • Loading branch information
betsytraran committed Jan 2, 2024
1 parent f29d3c9 commit ad0cfd9
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 ad0cfd9

Please sign in to comment.