aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/models/lists.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-04-27 17:40:41 +0000
committerMohamed Bassem <me@mbassem.com>2025-04-27 17:40:41 +0000
commit6178736d64180f9bc8954099c90d54aa2f9f35f5 (patch)
tree02c86e88010d22592258f621f1d2a6b498caeae2 /packages/trpc/models/lists.ts
parent28ca9d5f451b34c6221e9127eaf1d61841fa886c (diff)
downloadkarakeep-6178736d64180f9bc8954099c90d54aa2f9f35f5.tar.zst
fix: Fix smart lists not working in list search qualifiers. Fixes #845
Diffstat (limited to 'packages/trpc/models/lists.ts')
-rw-r--r--packages/trpc/models/lists.ts23
1 files changed, 17 insertions, 6 deletions
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(