import { getRequestEvent, query } from '$app/server'; import * as v from 'valibot'; import sql from '$lib/db/db.server'; import { verifyJWT } from '$lib/auth/index.server'; export const genDescription = query(async () => { await new Promise((f) => setTimeout(f, 1000)); return 'A matte black water bottle with a black lid and a "BKLYN BENTO" logo on the side, resting on a tree trunk in a forest.'; }); export const approveDenyItem = query( v.object({ id: v.number(), approved: v.boolean() }), async ({ id, approved }) => { const { cookies } = getRequestEvent(); const userPayload = verifyJWT(cookies); if (approved) { const reponse = await sql` UPDATE items SET approved_date = NOW(), emails = ( SELECT array_agg(DISTINCT email) FROM ( SELECT ${userPayload.email} AS email UNION ALL SELECT u.email FROM users u WHERE (u.settings->>'notifyAllApprovedInquiries')::boolean = true ) t ) WHERE id = ${id}; `; } else { await sql` DELETE FROM items WHERE id = ${id}; `; } } );