mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix
This commit is contained in:
@@ -9,3 +9,10 @@ export const NotificationType = {
|
|||||||
|
|
||||||
export type NotificationType =
|
export type NotificationType =
|
||||||
(typeof NotificationType)[keyof typeof NotificationType];
|
(typeof NotificationType)[keyof typeof NotificationType];
|
||||||
|
|
||||||
|
export type NotificationSettingKey =
|
||||||
|
| 'page.updated'
|
||||||
|
| 'page.user_mention'
|
||||||
|
| 'comment.user_mention'
|
||||||
|
| 'comment.created'
|
||||||
|
| 'comment.resolved';
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
|
import { NotificationSettingKey } from '../notification/notification.constants';
|
||||||
import { comparePasswordHash, diffAuditTrackedFields } from 'src/common/helpers/utils';
|
import { comparePasswordHash, diffAuditTrackedFields } from 'src/common/helpers/utils';
|
||||||
import { Workspace } from '@docmost/db/types/entity.types';
|
import { Workspace } from '@docmost/db/types/entity.types';
|
||||||
import { validateSsoEnforcement } from '../auth/auth.util';
|
import { validateSsoEnforcement } from '../auth/auth.util';
|
||||||
@@ -60,7 +61,7 @@ export class UserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationSettings: Record<string, string> = {
|
const notificationSettings: Record<string, NotificationSettingKey> = {
|
||||||
notificationPageUpdates: 'page.updated',
|
notificationPageUpdates: 'page.updated',
|
||||||
notificationPageUserMention: 'page.user_mention',
|
notificationPageUserMention: 'page.user_mention',
|
||||||
notificationCommentUserMention: 'comment.user_mention',
|
notificationCommentUserMention: 'comment.user_mention',
|
||||||
@@ -72,7 +73,7 @@ export class UserService {
|
|||||||
if (typeof updateUserDto[dtoField] !== 'undefined') {
|
if (typeof updateUserDto[dtoField] !== 'undefined') {
|
||||||
return this.userRepo.updateNotificationSetting(
|
return this.userRepo.updateNotificationSetting(
|
||||||
userId,
|
userId,
|
||||||
settingKey as any,
|
settingKey,
|
||||||
updateUserDto[dtoField],
|
updateUserDto[dtoField],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { PaginationOptions } from '../../pagination/pagination-options';
|
|||||||
import { executeWithCursorPagination } from '@docmost/db/pagination/cursor-pagination';
|
import { executeWithCursorPagination } from '@docmost/db/pagination/cursor-pagination';
|
||||||
import { ExpressionBuilder, sql } from 'kysely';
|
import { ExpressionBuilder, sql } from 'kysely';
|
||||||
import { jsonObjectFrom } from 'kysely/helpers/postgres';
|
import { jsonObjectFrom } from 'kysely/helpers/postgres';
|
||||||
|
import { NotificationSettingKey } from '../../../core/notification/notification.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserRepo {
|
export class UserRepo {
|
||||||
@@ -193,7 +194,7 @@ export class UserRepo {
|
|||||||
|
|
||||||
async updateNotificationSetting(
|
async updateNotificationSetting(
|
||||||
userId: string,
|
userId: string,
|
||||||
settingKey: 'page.updated' | 'page.user_mention' | 'comment.user_mention' | 'comment.created' | 'comment.resolved',
|
settingKey: NotificationSettingKey,
|
||||||
settingValue: boolean,
|
settingValue: boolean,
|
||||||
) {
|
) {
|
||||||
return await this.db
|
return await this.db
|
||||||
@@ -201,7 +202,7 @@ export class UserRepo {
|
|||||||
.set({
|
.set({
|
||||||
settings: sql`COALESCE(settings, '{}'::jsonb)
|
settings: sql`COALESCE(settings, '{}'::jsonb)
|
||||||
|| jsonb_build_object('notifications', COALESCE(settings->'notifications', '{}'::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(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where('id', '=', userId)
|
.where('id', '=', userId)
|
||||||
|
|||||||
Reference in New Issue
Block a user