Skip to content

Commit

Permalink
fix pageToken bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sshugsc committed Apr 16, 2024
1 parent dee7eda commit ce9e5ef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/clinicaltrialsgov/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ const formatDate = (date) => `${date.getFullYear()}-${date.getMonth() + 1}-${dat
const upload = async ({ conn, maxRecords, days }) => {
const source = await conn.addSource(SOURCE_DEFN);

let options = {};
let options,
optionsWithToken;

if (days) {
const startDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
Expand All @@ -320,7 +321,9 @@ const upload = async ({ conn, maxRecords, days }) => {

while (next) {
if (nextToken) {
options = { pageToken: nextToken, ...options };
optionsWithToken = { pageToken: nextToken, ...options };
} else {
optionsWithToken = options;
}
const trials = await requestWithRetry({
json: true,
Expand All @@ -331,7 +334,7 @@ const upload = async ({ conn, maxRecords, days }) => {
pageSize: 1000,
'query.cond': 'cancer',
sort: 'LastUpdatePostDate',
...options,
...optionsWithToken,
},
uri: BASE_URL,
});
Expand Down

0 comments on commit ce9e5ef

Please sign in to comment.