From 5ecdc36b7d60aa66b49e01e9fec8ba61ad537376 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Thu, 2 Jan 2025 13:00:58 +0200 Subject: feat: Add support for smart lists (#802) * feat: Add support for smart lists * i18n * Fix update list endpoint * Add a test for smart lists * Add header to the query explainer * Hide remove from lists in the smart context list * Add proper validation to list form --------- Co-authored-by: Deepak Kapoor <41769111+orthdron@users.noreply.github.com> --- packages/trpc/routers/bookmarks.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'packages/trpc/routers/bookmarks.ts') diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 3320b3b9..47ba623b 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -14,6 +14,7 @@ import { AssetTypes, bookmarkAssets, bookmarkLinks, + bookmarkLists, bookmarks, bookmarksInLists, bookmarkTags, @@ -33,6 +34,7 @@ import { triggerSearchReindex, } from "@hoarder/shared/queues"; import { getSearchIdxClient } from "@hoarder/shared/search"; +import { parseSearchQuery } from "@hoarder/shared/searchQueryParser"; import { BookmarkTypes, DEFAULT_NUM_BOOKMARKS_PER_PAGE, @@ -625,6 +627,34 @@ export const bookmarksAppRouter = router({ if (!input.limit) { input.limit = DEFAULT_NUM_BOOKMARKS_PER_PAGE; } + if (input.listId) { + const list = await ctx.db.query.bookmarkLists.findFirst({ + where: and( + eq(bookmarkLists.id, input.listId), + eq(bookmarkLists.userId, ctx.user.id), + ), + }); + if (!list) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "List not found", + }); + } + if (list.type === "smart") { + invariant(list.query); + const query = parseSearchQuery(list.query); + if (query.result !== "full") { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Found an invalid smart list query", + }); + } + if (query.matcher) { + input.ids = await getBookmarkIdsFromMatcher(ctx, query.matcher); + delete input.listId; + } + } + } const sq = ctx.db.$with("bookmarksSq").as( ctx.db -- cgit v1.2.3-70-g09d2