I have the following code:
init() {
const requisitionData = this.login().pipe(
map(response => response.data.token),
switchMap(loginData => this.getRequisitions(loginData)),
map(response => response.data),
map(requisitions => this.processRequisitions(requisitions)),
);
requisitionData.subscribe();
}
the getRequisitions()
calls a search endpoint that returns paginated data like so:
{
data: [{
title: '...',
reference: '...',
}],
meta: {
cursor: {
current_page: 1,
from: 1,
to: 50,
next: 2,
prev: null,
last_page: 2137,
per_page: 50,
total: 106824
}
},
message: 'Result List'
}
My current code in init()
only retrieves the first set of results (50 entries), performs some light processing on the data and saves it into the database (the processRequisitions
). How do I change my code to:
- Get the first set of result
- Get the value of
meta.cursor.last_page
- Pass the
next_page
value and call the same endpoint untillast_page
is reached.