aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/users.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-05-24 12:59:43 +0000
committerMohamed Bassem <me@mbassem.com>2025-05-24 12:59:43 +0000
commit09652176f97f11bc06f4c9b57a448e14744eac12 (patch)
tree5205f65bdef233328a7b4af010667c5b8c25f285 /packages/trpc/routers/users.ts
parent5f3fe5d1a1ad0abd2890283cbff45086cbfa442e (diff)
downloadkarakeep-09652176f97f11bc06f4c9b57a448e14744eac12.tar.zst
feat: Allow defaulting to reader mode when clicking on bookmarks. Fixes #662
Diffstat (limited to 'packages/trpc/routers/users.ts')
-rw-r--r--packages/trpc/routers/users.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts
index c56daaee..6f1f1145 100644
--- a/packages/trpc/routers/users.ts
+++ b/packages/trpc/routers/users.ts
@@ -10,11 +10,14 @@ import {
bookmarkTags,
highlights,
users,
+ userSettings,
} from "@karakeep/db/schema";
import { deleteUserAssets } from "@karakeep/shared/assetdb";
import serverConfig from "@karakeep/shared/config";
import {
zSignUpSchema,
+ zUpdateUserSettingsSchema,
+ zUserSettingsSchema,
zUserStatsResponseSchema,
zWhoAmIResponseSchema,
} from "@karakeep/shared/types/users";
@@ -59,6 +62,12 @@ export async function createUser(
email: users.email,
role: users.role,
});
+
+ // Insert user settings for the new user
+ await trx.insert(userSettings).values({
+ userId: result[0].id,
+ });
+
return result[0];
} catch (e) {
if (e instanceof SqliteError) {
@@ -242,4 +251,36 @@ export const usersAppRouter = router({
numHighlights,
};
}),
+ settings: authedProcedure
+ .output(zUserSettingsSchema)
+ .query(async ({ ctx }) => {
+ const settings = await ctx.db.query.userSettings.findFirst({
+ where: eq(userSettings.userId, ctx.user.id),
+ });
+ if (!settings) {
+ throw new TRPCError({
+ code: "NOT_FOUND",
+ message: "User settings not found",
+ });
+ }
+ return {
+ bookmarkClickAction: settings.bookmarkClickAction,
+ };
+ }),
+ updateSettings: authedProcedure
+ .input(zUpdateUserSettingsSchema)
+ .mutation(async ({ input, ctx }) => {
+ if (Object.keys(input).length === 0) {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: "No settings provided",
+ });
+ }
+ await ctx.db
+ .update(userSettings)
+ .set({
+ bookmarkClickAction: input.bookmarkClickAction,
+ })
+ .where(eq(userSettings.userId, ctx.user.id));
+ }),
});