96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import type {IUser} from '@/modelTypes/IUser'
|
|
import {NOTIFICATION_NAMES, type INotification} from '@/modelTypes/INotification'
|
|
|
|
import AbstractService from '@/services/abstractService'
|
|
import NotificationModel from '@/models/notification'
|
|
import {getTextIdentifier} from '@/models/task'
|
|
import {getDisplayName} from '@/models/user'
|
|
|
|
import {i18n} from '@/i18n'
|
|
|
|
export function getNotificationTitle(notificationItem: INotification, user: IUser | null) {
|
|
const notification = notificationItem.notification
|
|
let who: string
|
|
|
|
switch (notificationItem.name) {
|
|
case NOTIFICATION_NAMES.TASK_COMMENT:
|
|
return i18n.global.t('notification.items.taskComment.message', { taskIdentifier: getTextIdentifier(notification.task)})
|
|
case NOTIFICATION_NAMES.TASK_ASSIGNED:
|
|
who = (user !== null && user.id === notification.assignee.id)
|
|
? i18n.global.t('notification.items.taskAssigned.userYou')
|
|
: `${getDisplayName(notification.assignee)}`
|
|
|
|
return i18n.global.t('notification.items.taskAssigned.message', {
|
|
user: who,
|
|
taskIdentifier: getTextIdentifier(notification.task),
|
|
})
|
|
case NOTIFICATION_NAMES.TASK_DELETED:
|
|
// TODO: add user to title
|
|
return i18n.global.t('notification.items.taskDeleted.message', {
|
|
taskIdentifier: getTextIdentifier(notification.task),
|
|
})
|
|
case NOTIFICATION_NAMES.LIST_CREATED:
|
|
return i18n.global.t('notification.items.listCreated.message', {
|
|
listTitle: notification.list.title,
|
|
})
|
|
|
|
case NOTIFICATION_NAMES.TEAM_MEMBER_ADDED:
|
|
who = (user !== null && user.id === notification.member.id)
|
|
? i18n.global.t('notification.items.teamMemberAdded.userYou')
|
|
: `${getDisplayName(notification.member)}`
|
|
|
|
return i18n.global.t('notification.items.teamMemberAdded.message', {
|
|
user: who,
|
|
teamName: notification.team.name,
|
|
})
|
|
}
|
|
}
|
|
|
|
export function getNotificationRoute(notificationItem: INotification) {
|
|
const to = {
|
|
name: '',
|
|
params: {},
|
|
}
|
|
|
|
switch (notificationItem.name) {
|
|
case NOTIFICATION_NAMES.TASK_COMMENT:
|
|
case NOTIFICATION_NAMES.TASK_ASSIGNED:
|
|
to.name = 'task.detail'
|
|
to.params.id = notificationItem.notification.task.id
|
|
break
|
|
case NOTIFICATION_NAMES.TASK_DELETED:
|
|
// Nothing
|
|
break
|
|
case NOTIFICATION_NAMES.LIST_CREATED:
|
|
to.name = 'task.index'
|
|
to.params.listId = notificationItem.notification.list.id
|
|
break
|
|
case NOTIFICATION_NAMES.TEAM_MEMBER_ADDED:
|
|
to.name = 'teams.edit'
|
|
to.params.id = notificationItem.notification.team.id
|
|
break
|
|
default:
|
|
return undefined
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
export default class NotificationService extends AbstractService<INotification> {
|
|
constructor() {
|
|
super({
|
|
getAll: '/notifications',
|
|
update: '/notifications/{id}',
|
|
})
|
|
}
|
|
|
|
modelFactory(data) {
|
|
return new NotificationModel(data)
|
|
}
|
|
|
|
beforeUpdate(model) {
|
|
model.created = new Date(model.created).toISOString()
|
|
model.readAt = new Date(model.readAt).toISOString()
|
|
return model
|
|
}
|
|
} |