🐛 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,25 +1,46 @@
import { and, eq } from 'drizzle-orm'
import { useDb } from '~~/server/database/client'
import { expenseParticipants, expenses, participants } from '~~/server/database/schema'
import { and, eq } from 'drizzle-orm';
import { useDb } from '~~/server/database/client';
import {
expenseParticipants,
expenses,
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 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 [asPayer] = await db.select().from(expenses).where(eq(expenses.payerId, id)).limit(1)
const [asSplit] = await db.select().from(expenseParticipants).where(eq(expenseParticipants.participantId, id)).limit(1)
const [asPayer] = await db
.select()
.from(expenses)
.where(eq(expenses.payerId, id))
.limit(1);
const [asSplit] = await db
.select()
.from(expenseParticipants)
.where(eq(expenseParticipants.participantId, id))
.limit(1);
if (asPayer || asSplit) {
throw createError({ statusCode: 409, statusMessage: 'Cannot remove a participant with expenses or payments' })
throw createError({
statusCode: 409,
statusMessage: 'Cannot remove a participant with expenses or payments',
});
}
await db.delete(participants).where(eq(participants.id, id))
await db.delete(participants).where(eq(participants.id, id));
return { success: true }
})
return { success: true };
});