🐛 add env to useDb and apply prettier
tinyedge/deploy Deployed by TinyEdge

This commit is contained in:
2026-08-07 13:28:26 +02:00
parent 67727f96ab
commit cbe1b42f6e
54 changed files with 5492 additions and 2406 deletions
@@ -1,29 +1,40 @@
import { and, eq } from 'drizzle-orm'
import { isValidPaymentLink } from '~~/shared/utils/paymentLink'
import { useDb } from '~~/server/database/client'
import { participants } from '~~/server/database/schema'
import { and, eq } from 'drizzle-orm';
import { isValidPaymentLink } from '~~/shared/utils/paymentLink';
import { useDb } from '~~/server/database/client';
import { participants } from '~~/server/database/schema';
export default defineEventHandler(async (event) => {
const slug = getRouterParam(event, 'slug')!
const id = Number(getRouterParam(event, 'id'))
await getPotOrThrow(slug)
const slug = getRouterParam(event, 'slug')!;
const id = Number(getRouterParam(event, 'id'));
await getPotOrThrow(slug);
const body = await readBody(event)
const paymentLink = typeof body?.paymentLink === 'string' ? body.paymentLink.trim() : ''
const body = await readBody(event);
const paymentLink =
typeof body?.paymentLink === 'string' ? body.paymentLink.trim() : '';
if (paymentLink && !isValidPaymentLink(paymentLink)) {
throw createError({ statusCode: 400, statusMessage: 'paymentLink must be a valid http(s) URL' })
throw createError({
statusCode: 400,
statusMessage: 'paymentLink must be a valid http(s) URL',
});
}
const db = useDb()
const [existing] = await db.select().from(participants).where(and(eq(participants.id, id), eq(participants.potSlug, slug)))
const db = useDb(event);
const [existing] = await db
.select()
.from(participants)
.where(and(eq(participants.id, id), eq(participants.potSlug, slug)));
if (!existing) {
throw createError({ statusCode: 404, statusMessage: 'Participant not found' })
throw createError({
statusCode: 404,
statusMessage: 'Participant not found',
});
}
const [updated] = await db.update(participants)
const [updated] = await db
.update(participants)
.set({ paymentLink: paymentLink || null })
.where(eq(participants.id, id))
.returning()
.returning();
return updated
})
return updated;
});