(req, res)
| 10 | const client = new XataClient(); |
| 11 | |
| 12 | const handler: NextApiHandler = async (req, res) => { |
| 13 | const from = req.query.from; |
| 14 | |
| 15 | const testimonials = await client.db.testimonials |
| 16 | .sort("followers", "desc") |
| 17 | .getMany({ pagination: { size: 25, offset: parseFloat(String(from)) } }); |
| 18 | |
| 19 | res.end(JSON.stringify(randomizeArray(testimonials.map(t => { |
| 20 | const tweetId = getIdFromTweetUrl(String(t.tweet_url)); |
| 21 | if (t.ast === '""') { |
| 22 | console.info("No AST for", t.tweet_url, ". Adding...") |
| 23 | fetchTweetAst(getIdFromTweetUrl(tweetId)) |
| 24 | .then(ast => { |
| 25 | if (!ast) { |
| 26 | console.info("Couldn't get AST") |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | |
| 31 | return client.db.testimonials.update(t.id, { |
| 32 | ast: JSON.stringify(ast), |
| 33 | }).then(() => { console.info("Added.") }); |
| 34 | |
| 35 | }) |
| 36 | .catch((e) => { console.error(e) }); |
| 37 | } |
| 38 | return ({ id: tweetId, ast: JSON.parse(String(t.ast)) }) |
| 39 | })))) |
| 40 | } |
| 41 | |
| 42 | export default handler; |
nothing calls this directly
no test coverage detected