diff options
| author | MohamedBassem <me@mbassem.com> | 2025-08-03 08:57:04 -0700 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2025-08-03 08:58:22 -0700 |
| commit | 88c4035bc0c716ba03e10da760253da0aefe7b60 (patch) | |
| tree | d1a7798c705562a896ef045675e19583abdf9e59 /packages/trpc | |
| parent | 99653566f73187631d30cb52a66a982c455c1f9a (diff) | |
| download | karakeep-88c4035bc0c716ba03e10da760253da0aefe7b60.tar.zst | |
fix: Get rid of the userSetting table completely
Diffstat (limited to 'packages/trpc')
| -rw-r--r-- | packages/trpc/models/users.ts | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/packages/trpc/models/users.ts b/packages/trpc/models/users.ts index e6d443a7..a327e7db 100644 --- a/packages/trpc/models/users.ts +++ b/packages/trpc/models/users.ts @@ -15,7 +15,6 @@ import { passwordResetTokens, tagsOnBookmarks, users, - userSettings, verificationTokens, } from "@karakeep/db/schema"; import { deleteUserAssets } from "@karakeep/shared/assetdb"; @@ -120,10 +119,6 @@ export class User implements PrivacyAware { }) .returning(); - await trx.insert(userSettings).values({ - userId: result.id, - }); - return result; } catch (e) { if (e instanceof SqliteError) { @@ -143,21 +138,7 @@ export class User implements PrivacyAware { } static async getAll(ctx: AuthedContext): Promise<User[]> { - const dbUsers = await ctx.db - .select({ - id: users.id, - name: users.name, - email: users.email, - role: users.role, - password: users.password, - bookmarkQuota: users.bookmarkQuota, - storageQuota: users.storageQuota, - emailVerified: users.emailVerified, - image: users.image, - salt: users.salt, - browserCrawlingEnabled: users.browserCrawlingEnabled, - }) - .from(users); + const dbUsers = await ctx.db.select().from(users); return dbUsers.map((u) => new User(ctx, u)); } @@ -453,8 +434,13 @@ export class User implements PrivacyAware { } async getSettings(): Promise<z.infer<typeof zUserSettingsSchema>> { - const settings = await this.ctx.db.query.userSettings.findFirst({ - where: eq(userSettings.userId, this.user.id), + const settings = await this.ctx.db.query.users.findFirst({ + where: eq(users.id, this.user.id), + columns: { + bookmarkClickAction: true, + archiveDisplayBehaviour: true, + timezone: true, + }, }); if (!settings) { @@ -482,20 +468,23 @@ export class User implements PrivacyAware { } await this.ctx.db - .update(userSettings) + .update(users) .set({ bookmarkClickAction: input.bookmarkClickAction, archiveDisplayBehaviour: input.archiveDisplayBehaviour, timezone: input.timezone, }) - .where(eq(userSettings.userId, this.user.id)); + .where(eq(users.id, this.user.id)); } async getStats(): Promise<z.infer<typeof zUserStatsResponseSchema>> { - const userSet = await this.ctx.db.query.userSettings.findFirst({ - where: eq(userSettings.userId, this.user.id), + const userObj = await this.ctx.db.query.users.findFirst({ + where: eq(users.id, this.user.id), + columns: { + timezone: true, + }, }); - const userTimezone = userSet?.timezone || "UTC"; + const userTimezone = userObj?.timezone || "UTC"; const now = new Date(); const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000); |
