diff --git a/services/api/src/modules/notifications/domain/entities/notifications.ts b/services/api/src/modules/notifications/domain/entities/notifications.ts index 2d2ed300..4130769a 100644 --- a/services/api/src/modules/notifications/domain/entities/notifications.ts +++ b/services/api/src/modules/notifications/domain/entities/notifications.ts @@ -1,5 +1,5 @@ import { BaseEntity } from 'equipped' -import { NotificationData } from '../types' +import { NotificationData, NotificationType } from '../types' export class NotificationEntity extends BaseEntity { public readonly id: string @@ -34,6 +34,36 @@ export class NotificationEntity extends BaseEntity { this.createdAt = createdAt this.updatedAt = updatedAt } + + get link () { + const not = this.data + + if (not.type === NotificationType.VerificationAccepted) return '/settings/profile' + else if (not.type === NotificationType.VerificationRejected) return '/settings/profile' + else if (not.type === NotificationType.TutorRequestAccepted) return '/settings/profile' + else if (not.type === NotificationType.TutorRequestRejected) return '/settings/profile' + + else if (not.type === NotificationType.NewPurchase) return '/settings/wallet' + else if (not.type === NotificationType.NewPurchased) return `/${not.purchasedType}/${not.purchasedId}` + + else if (not.type === NotificationType.TutorAddedToConversation) return `/chats/${not.conversationId}` + + else if (not.type === NotificationType.UserJoinedGame) return `/games/${not.gameId}/lobby` + + else if (not.type === NotificationType.WithdrawalSuccessful) return '/settings/wallet' + else if (not.type === NotificationType.WithdrawalFailed) return '/settings/wallet' + else if (not.type === NotificationType.WalletFundSuccessful) return '/settings/wallet' + else if (not.type === NotificationType.SubscriptionSuccessful) return '/settings/subscription' + else if (not.type === NotificationType.SubscriptionFailed) return '/settings/subscription' + + else if (not.type === NotificationType.NewQuizAccessRequest) return `/quiz/${not.quizId}/edit` + else if (not.type === NotificationType.QuizAccessRequestGranted) return `/quiz/${not.quizId}/edit` + else if (not.type === NotificationType.QuizAccessRequestRejected) return `/quiz/${not.quizId}` + else if (not.type === NotificationType.QuizAccessMemberGranted) return `/quiz/${not.quizId}/edit` + else if (not.type === NotificationType.QuizAccessMemberRebuked) return `/quiz/${not.quizId}` + + return '/' + } } type NotificationConstructorArgs = { diff --git a/services/api/src/modules/notifications/domain/types/notifications.ts b/services/api/src/modules/notifications/domain/types/notifications.ts index 2b041151..7fdf26fc 100644 --- a/services/api/src/modules/notifications/domain/types/notifications.ts +++ b/services/api/src/modules/notifications/domain/types/notifications.ts @@ -35,7 +35,7 @@ export type NotificationData = | { type: NotificationType.WalletFundSuccessful, amount: number, currency: string } | { type: NotificationType.SubscriptionSuccessful, planId: string } | { type: NotificationType.SubscriptionFailed, planId: string } - | { type: NotificationType.NewQuizAccessRequest, userIds: string[] } + | { type: NotificationType.NewQuizAccessRequest, quizId: string, userIds: string[] } | { type: NotificationType.QuizAccessRequestGranted, quizId: string } | { type: NotificationType.QuizAccessRequestRejected, quizId: string } | { type: NotificationType.QuizAccessMemberGranted, quizId: string } diff --git a/services/api/src/modules/notifications/utils/changes/notifications.ts b/services/api/src/modules/notifications/utils/changes/notifications.ts index e68bd218..08a0e1cf 100644 --- a/services/api/src/modules/notifications/utils/changes/notifications.ts +++ b/services/api/src/modules/notifications/utils/changes/notifications.ts @@ -27,7 +27,7 @@ export const NotificationDbChangeCallbacks: DbChangeCallbacks title: 'New Quiz Edit Request', body: `Someone just requested access to edit your quiz: ${after.title}`, sendEmail: true, - data: { type: NotificationType.NewQuizAccessRequest, userIds: newRequests } + data: { type: NotificationType.NewQuizAccessRequest, quizId: after.id, userIds: newRequests } }) if (accepted.length) await sendNotification(accepted, { title: 'Quiz Edit Request Granted',