aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-12-28 12:30:24 +0000
committerMohamed Bassem <me@mbassem.com>2024-12-28 12:30:24 +0000
commit7956e9fa6772ab57a0794fb7cba7e9d9c0bd7878 (patch)
tree10d6e47afed8be007361cd40ec8b05fc52d6d4d9 /packages/trpc
parent7dd5b2bc8751911f86448e6c4619b2583d9a4b53 (diff)
downloadkarakeep-7956e9fa6772ab57a0794fb7cba7e9d9c0bd7878.tar.zst
feat: Implement the all highlights page. Fixes #620
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/routers/highlights.ts12
1 files changed, 5 insertions, 7 deletions
diff --git a/packages/trpc/routers/highlights.ts b/packages/trpc/routers/highlights.ts
index e4446679..86da560b 100644
--- a/packages/trpc/routers/highlights.ts
+++ b/packages/trpc/routers/highlights.ts
@@ -1,10 +1,11 @@
import { experimental_trpcMiddleware, TRPCError } from "@trpc/server";
-import { and, eq, lt, lte, or } from "drizzle-orm";
+import { and, desc, eq, lt, lte, or } from "drizzle-orm";
import { z } from "zod";
import { highlights } from "@hoarder/db/schema";
import {
DEFAULT_NUM_HIGHLIGHTS_PER_PAGE,
+ zGetAllHighlightsResponseSchema,
zHighlightSchema,
zNewHighlightSchema,
zUpdateHighlightSchema,
@@ -76,6 +77,7 @@ export const highlightsAppRouter = router({
eq(highlights.bookmarkId, input.bookmarkId),
eq(highlights.userId, ctx.user.id),
),
+ orderBy: [desc(highlights.createdAt), desc(highlights.id)],
});
return { highlights: results };
}),
@@ -102,12 +104,7 @@ export const highlightsAppRouter = router({
limit: z.number().optional().default(DEFAULT_NUM_HIGHLIGHTS_PER_PAGE),
}),
)
- .output(
- z.object({
- highlights: z.array(zHighlightSchema),
- nextCursor: zCursorV2.nullable(),
- }),
- )
+ .output(zGetAllHighlightsResponseSchema)
.query(async ({ input, ctx }) => {
const results = await ctx.db.query.highlights.findMany({
where: and(
@@ -123,6 +120,7 @@ export const highlightsAppRouter = router({
: undefined,
),
limit: input.limit + 1,
+ orderBy: [desc(highlights.createdAt), desc(highlights.id)],
});
let nextCursor: z.infer<typeof zCursorV2> | null = null;
if (results.length > input.limit) {