From 6178736d64180f9bc8954099c90d54aa2f9f35f5 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 27 Apr 2025 17:40:41 +0000 Subject: fix: Fix smart lists not working in list search qualifiers. Fixes #845 --- packages/trpc/models/lists.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'packages/trpc/models') diff --git a/packages/trpc/models/lists.ts b/packages/trpc/models/lists.ts index 4da127d2..d278f8d9 100644 --- a/packages/trpc/models/lists.ts +++ b/packages/trpc/models/lists.ts @@ -26,7 +26,7 @@ export abstract class List implements PrivacyAware { private static fromData( ctx: AuthedContext, data: ZBookmarkList & { userId: string }, - ) { + ): ManualList | SmartList { if (data.type === "smart") { return new SmartList(ctx, data); } else { @@ -34,6 +34,21 @@ export abstract class List implements PrivacyAware { } } + static async fromName( + ctx: AuthedContext, + name: string, + ): Promise<(ManualList | SmartList)[]> { + // Names are not unique, so we need to find all lists with the same name + const lists = await ctx.db.query.bookmarkLists.findMany({ + where: and( + eq(bookmarkLists.name, name), + eq(bookmarkLists.userId, ctx.user.id), + ), + }); + + return lists.map((l) => this.fromData(ctx, l)); + } + static async fromId( ctx: AuthedContext, id: string, @@ -51,11 +66,7 @@ export abstract class List implements PrivacyAware { message: "List not found", }); } - if (list.type === "smart") { - return new SmartList(ctx, list); - } else { - return new ManualList(ctx, list); - } + return this.fromData(ctx, list); } static async create( -- cgit v1.2.3-70-g09d2