Insert id property into return data

This commit is contained in:
regalijan 2023-10-19 16:49:53 -04:00
parent 589d07f1ac
commit 680d916894
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -47,7 +47,6 @@ export async function onRequestGet(context: RequestContext) {
const prefix = types[entryType]; const prefix = types[entryType];
const table = tables[entryType]; const table = tables[entryType];
const items = []; const items = [];
console.log(!showClosed)
const { results }: { results?: { created_at: number; id: string }[] } = const { results }: { results?: { created_at: number; id: string }[] } =
/* /*
This is normally VERY BAD and can lead to injection attacks This is normally VERY BAD and can lead to injection attacks
@ -62,9 +61,11 @@ export async function onRequestGet(context: RequestContext) {
if (results) if (results)
for (const { id } of results) { for (const { id } of results) {
items.push( const item = await context.env.DATA.get(`${prefix}_${id}`, {
await context.env.DATA.get(`${prefix}_${id}`, { type: "json" }) type: "json",
); });
if (item) items.push({ ...item, id });
} }
return new Response(JSON.stringify(items.filter((v) => v !== null)), { return new Response(JSON.stringify(items.filter((v) => v !== null)), {