-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpayloads.ts
34 lines (28 loc) · 851 Bytes
/
payloads.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { PrismaClient, payloads } from "@prisma/client"; // DB
// Setup Prisma
const client = new PrismaClient();
/**
* Collect payloads, given optional offset
* @param {number} offset to skip
* @returns {payloads[]}
*/
async function collectPayloads(offset: number = 0): Promise<payloads[]> {
// Collect payloads
return await client.payloads.findMany({
take: 25,
skip: offset,
orderBy: {
slot: "desc",
},
});
}
export async function get({ request: { url } }: { request: { url: string } }) {
// Collect query params
const params = new URL(url).searchParams;
const offset: string | null = params.get("offset");
// Setup prisma take
const take = offset ? Number(offset) : 0;
// Collect payloads
const data = await collectPayloads(take);
return new Response(JSON.stringify(data), { status: 200 });
}