Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

projects.ts

21 lines637 Bytes

1import type { NextApiRequest, NextApiResponse } from 'next'
2​
3export default (req: NextApiRequest, res: NextApiResponse) => {
4 const cursor =
5 typeof req.query.cursor === 'string' ? parseInt(req.query.cursor) || 0 : 0
6 const pageSize = 4
7​
8 const data = Array(pageSize)
9 .fill(0)
10 .map((_, i) => {
11 return {
12 name: 'Project ' + (i + cursor) + ` (server time: ${Date.now()})`,
13 id: i + cursor,
14 }
15 })
16​
17 const nextId = cursor < 20 ? data[data.length - 1].id + 1 : null
18 const previousId = cursor > -20 ? data[0].id - pageSize : null
19​
20 setTimeout(() => res.json({ data, nextId, previousId }), 300)