Skip to content

Commit 967a016

Browse files
committed
update GetAllNotificationsByUser use case
1 parent 1421988 commit 967a016

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

src/notifications/domain/models/Notification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ export interface Notification {
6767
dataFileId?: number
6868
dataFileDisplayName?: string
6969
currentCurationStatus?: string
70-
additionalInfo?: string
70+
additionalInfo?: Record<string, unknown>
7171
objectDeleted?: boolean
7272
}

src/notifications/domain/repositories/INotificationsRepository.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Notification } from '../models/Notification'
22

33
export interface INotificationsRepository {
4-
getAllNotificationsByUser(inAppNotificationFormat?: boolean): Promise<Notification[]>
4+
getAllNotificationsByUser(
5+
inAppNotificationFormat?: boolean,
6+
onlyUnread?: boolean,
7+
limit?: number,
8+
offset?: number
9+
): Promise<Notification[]>
510
deleteNotification(notificationId: number): Promise<void>
611
getUnreadNotificationsCount(): Promise<number>
712
markNotificationAsRead(notificationId: number): Promise<void>

src/notifications/domain/useCases/GetAllNotificationsByUser.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ export class GetAllNotificationsByUser implements UseCase<Notification[]> {
99
* Use case for retrieving all notifications for the current user.
1010
*
1111
* @param inAppNotificationFormat - Optional parameter to retrieve fields needed for in-app notifications
12+
* @param onlyUnread - Optional parameter to filter only unread notifications
13+
* @param limit - Optional parameter to limit the number of notifications returned
14+
* @param offset - Optional parameter to skip a number of notifications (for pagination)
1215
* @returns {Promise<Notification[]>} - A promise that resolves to an array of Notification instances.
1316
*/
14-
async execute(inAppNotificationFormat?: boolean): Promise<Notification[]> {
17+
async execute(
18+
inAppNotificationFormat?: boolean,
19+
onlyUnread?: boolean,
20+
limit?: number,
21+
offset?: number
22+
): Promise<Notification[]> {
1523
return (await this.notificationsRepository.getAllNotificationsByUser(
16-
inAppNotificationFormat
24+
inAppNotificationFormat,
25+
onlyUnread,
26+
limit,
27+
offset
1728
)) as Notification[]
1829
}
1930
}

src/notifications/infra/repositories/NotificationsRepository.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ export class NotificationsRepository extends ApiRepository implements INotificat
77
private readonly notificationsResourceName: string = 'notifications'
88

99
public async getAllNotificationsByUser(
10-
inAppNotificationFormat?: boolean
10+
inAppNotificationFormat?: boolean,
11+
onlyUnread?: boolean,
12+
limit?: number,
13+
offset?: number
1114
): Promise<Notification[]> {
12-
const queryParams = inAppNotificationFormat ? { inAppNotificationFormat: 'true' } : undefined
15+
const queryParams: Record<string, string | number> = {}
16+
17+
if (inAppNotificationFormat) queryParams.inAppNotificationFormat = 'true'
18+
if (onlyUnread) queryParams.onlyUnread = 'true'
19+
if (limit !== undefined) queryParams.limit = limit
20+
if (offset !== undefined) queryParams.offset = offset
21+
1322
return this.doGet(
1423
this.buildApiEndpoint(this.notificationsResourceName, 'all'),
1524
true,
16-
queryParams
25+
Object.keys(queryParams).length ? queryParams : undefined
1726
)
1827
.then((response) => {
1928
const notifications = response.data.data.notifications

src/notifications/infra/transformers/NotificationPayload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export interface NotificationPayload {
2525
dataFileId?: number
2626
dataFileDisplayName?: string
2727
currentCurationStatus?: string
28-
additionalInfo?: string
28+
additionalInfo?: Record<string, unknown>
2929
objectDeleted?: boolean
3030
}

test/functional/notifications/GetAllNotificationsByUser.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ describe('execute', () => {
3434
expect(notifications[0]).toHaveProperty('sentTimestamp')
3535
expect(notifications[0]).toHaveProperty('displayAsRead')
3636
})
37+
test('should have correct in-app notification properties when filter and paging params are set', async () => {
38+
const notifications = await getAllNotificationsByUser.execute(true, true, 1, 0)
39+
40+
expect(notifications[0]).toHaveProperty('id')
41+
expect(notifications[0]).toHaveProperty('type')
42+
expect(notifications[0]).toHaveProperty('sentTimestamp')
43+
expect(notifications[0]).toHaveProperty('displayAsRead')
44+
expect(notifications.length).toBeLessThanOrEqual(1)
45+
})
3746
})

0 commit comments

Comments
 (0)