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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user