From feacb8c7ac410ed132642c5b97dfb995d318cb33 Mon Sep 17 00:00:00 2001 From: Matt Ciaccio Date: Thu, 23 Apr 2026 23:46:03 +0200 Subject: [PATCH] fix(yachts): run owner existence check inside transaction --- src/lib/services/yachts.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/services/yachts.service.ts b/src/lib/services/yachts.service.ts index 5f21206..802a2af 100644 --- a/src/lib/services/yachts.service.ts +++ b/src/lib/services/yachts.service.ts @@ -20,14 +20,15 @@ interface AuditMeta { async function assertOwnerExists( portId: string, owner: { type: 'client' | 'company'; id: string }, + tx: typeof db, ): Promise { if (owner.type === 'client') { - const client = await db.query.clients.findFirst({ + const client = await tx.query.clients.findFirst({ where: and(eq(clients.id, owner.id), eq(clients.portId, portId)), }); if (!client) throw new ValidationError('owner not found'); } else { - const company = await db.query.companies.findFirst({ + const company = await tx.query.companies.findFirst({ where: and(eq(companies.id, owner.id), eq(companies.portId, portId)), }); if (!company) throw new ValidationError('owner not found'); @@ -36,7 +37,7 @@ async function assertOwnerExists( export async function createYacht(portId: string, data: CreateYachtInput, meta: AuditMeta) { return await db.transaction(async (tx) => { - await assertOwnerExists(portId, data.owner); + await assertOwnerExists(portId, data.owner, tx as unknown as typeof db); const [yacht] = await tx .insert(yachts)