From d034fce11b7db0867b0763fff4a2eaa664b1c040 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 31 Mar 2026 00:35:33 +0100 Subject: [PATCH] fix --- .../server/src/core/notification/notification.constants.ts | 7 +++++++ apps/server/src/core/user/user.service.ts | 5 +++-- apps/server/src/database/repos/user/user.repo.ts | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/server/src/core/notification/notification.constants.ts b/apps/server/src/core/notification/notification.constants.ts index 140c3636..96393e47 100644 --- a/apps/server/src/core/notification/notification.constants.ts +++ b/apps/server/src/core/notification/notification.constants.ts @@ -9,3 +9,10 @@ export const NotificationType = { export type NotificationType = (typeof NotificationType)[keyof typeof NotificationType]; + +export type NotificationSettingKey = + | 'page.updated' + | 'page.user_mention' + | 'comment.user_mention' + | 'comment.created' + | 'comment.resolved'; diff --git a/apps/server/src/core/user/user.service.ts b/apps/server/src/core/user/user.service.ts index 723eb716..771c48d6 100644 --- a/apps/server/src/core/user/user.service.ts +++ b/apps/server/src/core/user/user.service.ts @@ -7,6 +7,7 @@ import { UnauthorizedException, } from '@nestjs/common'; import { UpdateUserDto } from './dto/update-user.dto'; +import { NotificationSettingKey } from '../notification/notification.constants'; import { comparePasswordHash, diffAuditTrackedFields } from 'src/common/helpers/utils'; import { Workspace } from '@docmost/db/types/entity.types'; import { validateSsoEnforcement } from '../auth/auth.util'; @@ -60,7 +61,7 @@ export class UserService { ); } - const notificationSettings: Record = { + const notificationSettings: Record = { notificationPageUpdates: 'page.updated', notificationPageUserMention: 'page.user_mention', notificationCommentUserMention: 'comment.user_mention', @@ -72,7 +73,7 @@ export class UserService { if (typeof updateUserDto[dtoField] !== 'undefined') { return this.userRepo.updateNotificationSetting( userId, - settingKey as any, + settingKey, updateUserDto[dtoField], ); } diff --git a/apps/server/src/database/repos/user/user.repo.ts b/apps/server/src/database/repos/user/user.repo.ts index 2a68200d..eaaa318e 100644 --- a/apps/server/src/database/repos/user/user.repo.ts +++ b/apps/server/src/database/repos/user/user.repo.ts @@ -13,6 +13,7 @@ import { PaginationOptions } from '../../pagination/pagination-options'; import { executeWithCursorPagination } from '@docmost/db/pagination/cursor-pagination'; import { ExpressionBuilder, sql } from 'kysely'; import { jsonObjectFrom } from 'kysely/helpers/postgres'; +import { NotificationSettingKey } from '../../../core/notification/notification.constants'; @Injectable() export class UserRepo { @@ -193,7 +194,7 @@ export class UserRepo { async updateNotificationSetting( userId: string, - settingKey: 'page.updated' | 'page.user_mention' | 'comment.user_mention' | 'comment.created' | 'comment.resolved', + settingKey: NotificationSettingKey, settingValue: boolean, ) { return await this.db @@ -201,7 +202,7 @@ export class UserRepo { .set({ settings: sql`COALESCE(settings, '{}'::jsonb) || jsonb_build_object('notifications', COALESCE(settings->'notifications', '{}'::jsonb) - || jsonb_build_object(${settingKey}, ${sql.lit(settingValue)}))`, + || jsonb_build_object(${sql.lit(settingKey)}, ${sql.lit(settingValue)}))`, updatedAt: new Date(), }) .where('id', '=', userId)