MCPcopy Create free account
hub / github.com/TejasQ/tejaskumar.com / handler

Function handler

pages/api/testimonials.ts:12–40  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

10const client = new XataClient();
11
12const 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
42export default handler;

Callers

nothing calls this directly

Calls 2

randomizeArrayFunction · 0.90
getIdFromTweetUrlFunction · 0.90

Tested by

no test coverage detected