fbla26/src/lib/db/items.remote.ts
DragonDuck24 505434a2d8
All checks were successful
ci / docker_image (push) Successful in 3m18s
ci / deploy (push) Successful in 28s
inquiries and claims
2026-02-05 19:09:34 -06:00

42 lines
1.1 KiB
TypeScript

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};
`;
}
}
);