fix(server): add mode property on mention doc input (#10853)

This commit is contained in:
fengmk2
2025-03-14 08:23:27 +00:00
parent c31d01b2c2
commit 114e89961f
9 changed files with 180 additions and 13 deletions

View File

@@ -6,13 +6,13 @@ import ava, { TestFn } from 'ava';
import { createTestingModule, type TestingModule } from '../../__tests__/utils';
import { Config } from '../../base/config';
import {
DocMode,
Models,
NotificationLevel,
NotificationType,
User,
Workspace,
} from '../../models';
interface Context {
config: Config;
module: TestingModule;
@@ -71,6 +71,7 @@ test('should create a mention notification with default level', async t => {
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -94,6 +95,7 @@ test('should create a mention notification with custom level', async t => {
id: docId,
title: 'doc-title',
elementId: 'elementId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -118,6 +120,7 @@ test('should mark a mention notification as read', async t => {
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -174,6 +177,7 @@ test('should find many notifications by user id, order by createdAt descending',
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -204,6 +208,7 @@ test('should find many notifications by user id, filter read notifications', asy
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -234,6 +239,7 @@ test('should clean expired notifications', async t => {
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -270,6 +276,7 @@ test('should not clean unexpired notifications', async t => {
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -290,6 +297,7 @@ test('should find many notifications by user id, order by createdAt descending,
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.edgeless,
},
createdByUserId: createdBy.id,
},
@@ -357,6 +365,7 @@ test('should count notifications by user id, exclude read notifications', async
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
@@ -385,6 +394,7 @@ test('should count notifications by user id, include read notifications', async
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},

View File

@@ -13,7 +13,13 @@ export interface Doc {
export type DocEditor = Pick<User, 'id' | 'name' | 'avatarUrl'>;
// TODO(@fengmk2): only used it inside the DocModel, use DocMode instead on the other places
export enum PublicDocMode {
Page,
Edgeless,
}
export enum DocMode {
page = 'page',
edgeless = 'edgeless',
}

View File

@@ -9,6 +9,7 @@ import { z } from 'zod';
import { PaginationInput } from '../base';
import { BaseModel } from './base';
import { DocMode } from './common';
export { NotificationLevel, NotificationType };
export type { Notification };
@@ -30,11 +31,15 @@ export const MentionDocSchema = z.object({
id: IdSchema,
// Allow empty string, will display as `Untitled` at frontend
title: z.string().trim().max(255),
mode: z.nativeEnum(DocMode),
// blockId or elementId is required at least one
blockId: IdSchema.optional(),
elementId: IdSchema.optional(),
});
export type MentionDoc = z.infer<typeof MentionDocSchema>;
export type MentionDocCreate = z.input<typeof MentionDocSchema>;
const MentionNotificationBodySchema = z.object({
workspaceId: IdSchema,
createdByUserId: IdSchema,