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)