-
Notifications
You must be signed in to change notification settings - Fork 11
Use Cases for Get Notifications and Delete Notifications #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ofahimIQSS
merged 9 commits into
develop
from
334-create-use-cases-for-get-notifications-and-delete-notifications
Aug 22, 2025
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c49ec5
feat: update notification usecases
ChengShi-1 3c12fbe
fix: testcases
ChengShi-1 252e08c
fix: naming of delete notification
ChengShi-1 008b3aa
Merge branch 'develop' into 334-create-use-cases-for-get-notification…
ChengShi-1 e93174e
feat: update get notification parameter
ChengShi-1 541e892
feat: display as read
ChengShi-1 de95d37
fix on tests
ChengShi-1 e087a57
update env. variables
ChengShi-1 b61f8cf
fix: update naming and test
ChengShi-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| export enum NotificationType { | ||
| ASSIGNROLE = 'ASSIGNROLE', | ||
| REVOKEROLE = 'REVOKEROLE', | ||
| CREATEDV = 'CREATEDV', | ||
| CREATEDS = 'CREATEDS', | ||
| CREATEACC = 'CREATEACC', | ||
| SUBMITTEDDS = 'SUBMITTEDDS', | ||
| RETURNEDDS = 'RETURNEDDS', | ||
| PUBLISHEDDS = 'PUBLISHEDDS', | ||
| REQUESTFILEACCESS = 'REQUESTFILEACCESS', | ||
| GRANTFILEACCESS = 'GRANTFILEACCESS', | ||
| REJECTFILEACCESS = 'REJECTFILEACCESS', | ||
| FILESYSTEMIMPORT = 'FILESYSTEMIMPORT', | ||
| CHECKSUMIMPORT = 'CHECKSUMIMPORT', | ||
| CHECKSUMFAIL = 'CHECKSUMFAIL', | ||
| CONFIRMEMAIL = 'CONFIRMEMAIL', | ||
| APIGENERATED = 'APIGENERATED', | ||
| INGESTCOMPLETED = 'INGESTCOMPLETED', | ||
| INGESTCOMPLETEDWITHERRORS = 'INGESTCOMPLETEDWITHERRORS', | ||
| PUBLISHFAILED_PIDREG = 'PUBLISHFAILED_PIDREG', | ||
| WORKFLOW_SUCCESS = 'WORKFLOW_SUCCESS', | ||
| WORKFLOW_FAILURE = 'WORKFLOW_FAILURE', | ||
| STATUSUPDATED = 'STATUSUPDATED', | ||
| DATASETCREATED = 'DATASETCREATED', | ||
| DATASETMENTIONED = 'DATASETMENTIONED', | ||
| GLOBUSUPLOADCOMPLETED = 'GLOBUSUPLOADCOMPLETED', | ||
| GLOBUSUPLOADCOMPLETEDWITHERRORS = 'GLOBUSUPLOADCOMPLETEDWITHERRORS', | ||
| GLOBUSDOWNLOADCOMPLETED = 'GLOBUSDOWNLOADCOMPLETED', | ||
| GLOBUSDOWNLOADCOMPLETEDWITHERRORS = 'GLOBUSDOWNLOADCOMPLETEDWITHERRORS', | ||
| REQUESTEDFILEACCESS = 'REQUESTEDFILEACCESS', | ||
| GLOBUSUPLOADREMOTEFAILURE = 'GLOBUSUPLOADREMOTEFAILURE', | ||
| GLOBUSUPLOADLOCALFAILURE = 'GLOBUSUPLOADLOCALFAILURE', | ||
| PIDRECONCILED = 'PIDRECONCILED' | ||
| } | ||
|
|
||
| export interface RoleAssignment { | ||
| id: number | ||
| assignee: string | ||
| definitionPointId: number | ||
| roleId: number | ||
| roleName: string | ||
| _roleAlias: string | ||
| } | ||
|
|
||
| export interface Notification { | ||
| id: number | ||
| type: NotificationType | ||
| subjectText?: string | ||
| messageText?: string | ||
| sentTimestamp: string | ||
| displayAsRead: boolean | ||
| installationBrandName?: string | ||
| userGuidesBaseUrl?: string | ||
| userGuidesVersion?: string | ||
| userGuidesSectionPath?: string | ||
| roleAssignments?: RoleAssignment[] | ||
| dataverseAlias?: string | ||
| dataverseDisplayName?: string | ||
| datasetPersistentIdentifier?: string | ||
| datasetDisplayName?: string | ||
| ownerPersistentIdentifier?: string | ||
| ownerAlias?: string | ||
| ownerDisplayName?: string | ||
| requestorFirstName?: string | ||
| requestorLastName?: string | ||
| requestorEmail?: string | ||
| dataFileId?: number | ||
| dataFileDisplayName?: string | ||
| currentCurationStatus?: string | ||
| additionalInfo?: string | ||
| objectDeleted?: boolean | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/notifications/domain/repositories/INotificationsRepository.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Notification } from '../models/Notification' | ||
|
|
||
| export interface INotificationsRepository { | ||
| getAllNotificationsByUser(inAppNotificationFormat?: boolean): Promise<Notification[]> | ||
| deleteNotification(notificationId: number): Promise<void> | ||
| getUnreadCount(): Promise<number> | ||
| markAsRead(notificationId: number): Promise<void> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { INotificationsRepository } from '../repositories/INotificationsRepository' | ||
|
|
||
| /** | ||
| * Use case for deleting a specific notification for the current user. | ||
| * | ||
| * @param notificationId - The ID of the notification to delete. | ||
| * @returns {Promise<void>} - A promise that resolves when the notification is deleted. | ||
| */ | ||
| export class DeleteNotification implements UseCase<void> { | ||
| constructor(private readonly notificationsRepository: INotificationsRepository) {} | ||
|
|
||
| async execute(notificationId: number): Promise<void> { | ||
| return this.notificationsRepository.deleteNotification(notificationId) | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/notifications/domain/useCases/GetAllNotificationsByUser.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { Notification } from '../models/Notification' | ||
| import { INotificationsRepository } from '../repositories/INotificationsRepository' | ||
|
|
||
| export class GetAllNotificationsByUser implements UseCase<Notification[]> { | ||
| constructor(private readonly notificationsRepository: INotificationsRepository) {} | ||
|
|
||
| /** | ||
| * Use case for retrieving all notifications for the current user. | ||
| * | ||
| * @param inAppNotificationFormat - Optional parameter to retrieve fields needed for in-app notifications | ||
| * @returns {Promise<Notification[]>} - A promise that resolves to an array of Notification instances. | ||
| */ | ||
| async execute(inAppNotificationFormat?: boolean): Promise<Notification[]> { | ||
| return (await this.notificationsRepository.getAllNotificationsByUser( | ||
| inAppNotificationFormat | ||
| )) as Notification[] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { INotificationsRepository } from '../repositories/INotificationsRepository' | ||
|
|
||
| export class GetUnreadCount implements UseCase<number> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to follow the naming convention we have in other use cases, change to GetUnreadNotificationsCount? |
||
| private notificationsRepository: INotificationsRepository | ||
|
|
||
| constructor(notificationsRepository: INotificationsRepository) { | ||
| this.notificationsRepository = notificationsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Use case for retrieving the number of unread notifications for the current user. | ||
| * | ||
| * @returns {Promise<number>} - A promise that resolves to the number of unread notifications. | ||
| */ | ||
| async execute(): Promise<number> { | ||
| return await this.notificationsRepository.getUnreadCount() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { INotificationsRepository } from '../repositories/INotificationsRepository' | ||
|
|
||
| export class MarkAsRead implements UseCase<void> { | ||
|
ChengShi-1 marked this conversation as resolved.
Outdated
|
||
| private notificationsRepository: INotificationsRepository | ||
|
|
||
| constructor(notificationsRepository: INotificationsRepository) { | ||
| this.notificationsRepository = notificationsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Use case for marking a notification as read. | ||
| * | ||
| * @param notificationId - The ID of the notification to mark as read. | ||
| * @returns {Promise<void>} - A promise that resolves when the notification is marked as read. | ||
| */ | ||
| async execute(notificationId: number): Promise<void> { | ||
| return await this.notificationsRepository.markAsRead(notificationId) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { NotificationsRepository } from './infra/repositories/NotificationsRepository' | ||
| import { GetAllNotificationsByUser } from './domain/useCases/GetAllNotificationsByUser' | ||
| import { DeleteNotification } from './domain/useCases/DeleteNotification' | ||
| import { GetUnreadCount } from './domain/useCases/GetUnreadCount' | ||
| import { MarkAsRead } from './domain/useCases/MarkAsRead' | ||
|
|
||
| const notificationsRepository = new NotificationsRepository() | ||
|
|
||
| const getAllNotificationsByUser = new GetAllNotificationsByUser(notificationsRepository) | ||
| const deleteNotification = new DeleteNotification(notificationsRepository) | ||
| const getUnreadCount = new GetUnreadCount(notificationsRepository) | ||
| const markAsRead = new MarkAsRead(notificationsRepository) | ||
|
|
||
| export { getAllNotificationsByUser, deleteNotification, getUnreadCount, markAsRead } | ||
|
|
||
| export { Notification, NotificationType, RoleAssignment } from './domain/models/Notification' |
46 changes: 46 additions & 0 deletions
46
src/notifications/infra/repositories/NotificationsRepository.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { ApiRepository } from '../../../core/infra/repositories/ApiRepository' | ||
| import { INotificationsRepository } from '../../domain/repositories/INotificationsRepository' | ||
| import { Notification } from '../../domain/models/Notification' | ||
|
|
||
| export class NotificationsRepository extends ApiRepository implements INotificationsRepository { | ||
| private readonly notificationsResourceName: string = 'notifications' | ||
|
|
||
| public async getAllNotificationsByUser( | ||
| inAppNotificationFormat?: boolean | ||
| ): Promise<Notification[]> { | ||
| const queryParams = inAppNotificationFormat ? { inAppNotificationFormat: 'true' } : undefined | ||
| return this.doGet( | ||
| this.buildApiEndpoint(this.notificationsResourceName, 'all'), | ||
| true, | ||
| queryParams | ||
| ) | ||
| .then((response) => response.data.data.notifications as Notification[]) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } | ||
|
|
||
| public async deleteNotification(notificationId: number): Promise<void> { | ||
| return this.doDelete( | ||
| this.buildApiEndpoint(this.notificationsResourceName, notificationId.toString()) | ||
| ) | ||
| .then(() => undefined) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } | ||
|
|
||
| public async getUnreadCount(): Promise<number> { | ||
| return this.doGet( | ||
| this.buildApiEndpoint(this.notificationsResourceName, 'unreadCount'), | ||
| true | ||
| ).then((response) => response.data.data.unreadCount as number) | ||
| } | ||
|
|
||
| public async markAsRead(notificationId: number): Promise<void> { | ||
| return this.doPut( | ||
| this.buildApiEndpoint(this.notificationsResourceName, 'markAsRead', notificationId), | ||
| {} | ||
| ).then(() => undefined) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { ApiConfig, deleteNotification, getAllNotificationsByUser, WriteError } from '../../../src' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
|
|
||
| describe('execute', () => { | ||
| beforeEach(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| }) | ||
|
|
||
| test('should successfully delete a notification for authenticated user', async () => { | ||
| const notifications = await getAllNotificationsByUser.execute() | ||
| const notificationId = notifications[notifications.length - 1].id | ||
|
|
||
| await deleteNotification.execute(notificationId) | ||
|
|
||
| const notificationsAfterDelete = await getAllNotificationsByUser.execute() | ||
| expect(notificationsAfterDelete.length).toBe(notifications.length - 1) | ||
| }) | ||
|
|
||
| test('should throw an error when the notification id does not exist', async () => { | ||
| await expect(deleteNotification.execute(123)).rejects.toThrow(WriteError) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.