Skip to content

Commit

Permalink
feat: notification link
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinand11 committed Dec 8, 2023
1 parent d64d3db commit 7a22c23
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const NotificationDbChangeCallbacks: DbChangeCallbacks<NotificationFromMo
const user = await UsersUseCases.find(after.userId)
if (user) {
const content = await readEmailFromPug('emails/newNotification.pug', {
notification: after, meta: { link: clientDomain }
notification: after, meta: { link: `${clientDomain}${after.link}` }
})
await publishers.SENDMAIL.publish({
from: EmailsList.NO_REPLY, to: user.bio.email, subject: after.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class QuestionEntity extends BaseEntity {
strip () {
return {
...this.toJSON(),
explanation: undefined,
explanation: '',
data: this.strippedData,
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/modules/study/utils/changes/quizzes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const QuizDbChangeCallbacks: DbChangeCallbacks<QuizFromModel, QuizEntity>
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',
Expand Down

0 comments on commit 7a22c23

Please sign in to comment.