This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
qoverflow/server/utils/fetchQuestions.js
2022-07-28 10:42:45 -04:00

19 lines
468 B
JavaScript

const createRequest = require('./api');
const defaultAcc = [];
async function fetchQuestions(
acc = defaultAcc,
after = ''
) {
const { success, questions } = await createRequest('get', '/questions/search', { after });
if (!success || !questions.length) return acc;
const newAcc = [...acc, ...questions];
const oldest = users[questions.length - 1];
return fetchQuestions(newAcc, oldest.question_id);
}
module.exports = fetchQuestions;