feat(yachts): list + owner-scoped list + autocomplete

Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.

`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-24 00:03:36 +02:00
parent 8a5cd1ef0e
commit 7c408cf975
3 changed files with 283 additions and 4 deletions

View File

@@ -72,15 +72,22 @@ export async function makeYacht(args: {
portId: string;
ownerType: 'client' | 'company';
ownerId: string;
name?: string;
status?: 'active' | 'retired' | 'sold_away';
hullNumber?: string;
registration?: string;
overrides?: Partial<NewYacht>;
}): Promise<Yacht> {
const [yacht] = await db
.insert(yachts)
.values({
portId: args.portId,
name: args.overrides?.name ?? `Yacht ${Math.random().toString(36).slice(2, 8)}`,
name: args.name ?? args.overrides?.name ?? `Yacht ${Math.random().toString(36).slice(2, 8)}`,
currentOwnerType: args.ownerType,
currentOwnerId: args.ownerId,
...(args.status !== undefined ? { status: args.status } : {}),
...(args.hullNumber !== undefined ? { hullNumber: args.hullNumber } : {}),
...(args.registration !== undefined ? { registration: args.registration } : {}),
...args.overrides,
})
.returning();