diff --git a/src/app/features/notification/model/notification-event.ts b/src/app/features/notification/model/notification-event.ts index afbc4083de..a3ef17590e 100644 --- a/src/app/features/notification/model/notification-event.ts +++ b/src/app/features/notification/model/notification-event.ts @@ -1,6 +1,7 @@ import { Entity } from "../../../core/entity/model/entity"; import { DatabaseField } from "../../../core/entity/database-field.decorator"; import { DatabaseEntity } from "../../../core/entity/database-entity.decorator"; +import { NotificationType } from "./notification-config"; /** * This represents one specific notification event for one specific user, @@ -8,10 +9,43 @@ import { DatabaseEntity } from "../../../core/entity/database-entity.decorator"; */ @DatabaseEntity("NotificationEvent") export class NotificationEvent extends Entity { + /* + * The title of the notification. + */ @DatabaseField() title: string; + + /* + * The body of the notification. + */ @DatabaseField() body: string; + + /* + * The URL to redirect the user to when the notification is clicked. + */ @DatabaseField() actionURL: string; + + /* + * The user ID for whom the notification is intended + */ @DatabaseField() notificationFor: string; + + /* + * The notification token to be used for the notification. + */ @DatabaseField() notificationToken: string; + + /* + * The type of notification. + */ + @DatabaseField() notificationType: NotificationType; + + /* + * The entity type of the notification. + */ + @DatabaseField() entityType: string; + + /* + * The status of the notification. + */ @DatabaseField() readStatus: boolean; } diff --git a/src/app/features/notification/notification.component.ts b/src/app/features/notification/notification.component.ts index 69205541b0..45ec0380cb 100644 --- a/src/app/features/notification/notification.component.ts +++ b/src/app/features/notification/notification.component.ts @@ -135,6 +135,29 @@ export class NotificationComponent implements OnInit { await this.entityMapper.remove(notification); } + private generateNotificationActionURL( + notification: NotificationEvent, + ): string { + const routes = this.router.config; + let actionURL = ""; + + const entityRoute = routes.find( + (route) => route.data?.config?.entityType === notification.entityType, + ); + + switch (notification.notificationType) { + case "entity_change": + if (entityRoute) { + actionURL = `/${entityRoute.path}`; + } + break; + default: + break; + } + + return actionURL; + } + /** * Updates the read status of a selected notification. * Handles notification events by redirecting the user to the corresponding action URL. @@ -142,8 +165,9 @@ export class NotificationComponent implements OnInit { */ async notificationClicked(notification: NotificationEvent) { await this.updateReadStatus([notification], true); - if (!notification.actionURL) return; - await this.router.navigate([notification.actionURL]); + const actionURL = this.generateNotificationActionURL(notification); + if (!actionURL) return; + await this.router.navigate([actionURL]); } // TODO: remove test code before final merge