feat(server): support read all notifications (#13083)

close AF-2719



#### PR Dependency Tree


* **PR #13083** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added the ability to mark all notifications as read with a single
action.
  
* **Bug Fixes**
  * Ensured notifications marked as read are no longer shown as unread.

* **Tests**
* Introduced new tests to verify the functionality of marking all
notifications as read.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-07-08 15:19:45 +08:00
committed by GitHub
parent 6fd9524521
commit db79c00ea7
9 changed files with 122 additions and 0 deletions
@@ -430,3 +430,32 @@ test('should create a comment mention notification', async t => {
t.is(notification.body.commentId, commentId);
t.is(notification.body.replyId, replyId);
});
test('should mark all notifications as read', async t => {
await models.notification.createMention({
userId: user.id,
body: {
workspaceId: workspace.id,
doc: {
id: docId,
title: 'doc-title',
blockId: 'blockId',
mode: DocMode.page,
},
createdByUserId: createdBy.id,
},
});
await models.notification.createInvitation({
userId: user.id,
body: {
workspaceId: workspace.id,
createdByUserId: createdBy.id,
inviteId: randomUUID(),
},
});
await models.notification.markAllAsRead(user.id);
const notifications = await models.notification.findManyByUserId(user.id);
t.is(notifications.length, 0);
});
@@ -261,6 +261,18 @@ export class NotificationModel extends BaseModel {
});
}
async markAllAsRead(userId: string) {
const { count } = await this.db.notification.updateMany({
where: { userId },
data: {
read: true,
},
});
this.logger.log(
`Marked all notifications as read for user ${userId}, count: ${count}`
);
}
/**
* Find many notifications by user id, exclude read notifications by default
*/