2021-11-27 19:53:05 +00:00
|
|
|
import { parseDate, Notification } from '@skolplattformen/api'
|
2021-04-01 15:46:13 +00:00
|
|
|
import { etjanst } from './etjanst'
|
|
|
|
|
|
|
|
export const notification = ({
|
2021-09-30 20:06:45 +00:00
|
|
|
notification: { messageid, dateCreated, dateModified },
|
2021-04-01 15:46:13 +00:00
|
|
|
notificationMessage: {
|
|
|
|
messages: {
|
|
|
|
message: {
|
|
|
|
category,
|
|
|
|
messagetext,
|
|
|
|
linkbackurl,
|
|
|
|
messagetype: { type },
|
|
|
|
sender: { name },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}: any): Notification => ({
|
|
|
|
id: messageid,
|
|
|
|
message: messagetext,
|
|
|
|
sender: name,
|
|
|
|
url: linkbackurl,
|
|
|
|
dateCreated: parseDate(dateCreated) || '',
|
2021-09-30 20:06:45 +00:00
|
|
|
dateModified: parseDate(dateModified) || '',
|
2021-04-01 15:46:13 +00:00
|
|
|
category,
|
|
|
|
type,
|
|
|
|
})
|
|
|
|
|
2022-04-24 18:26:16 +00:00
|
|
|
const notificationsSort = (
|
|
|
|
item1: Notification,
|
|
|
|
item2: Notification
|
|
|
|
): number => {
|
2021-10-01 07:24:25 +00:00
|
|
|
const m1 = item1.dateModified || item1.dateCreated
|
|
|
|
const m2 = item2.dateModified || item2.dateCreated
|
|
|
|
return m1 < m2 ? 1 : -1
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:46:13 +00:00
|
|
|
export const notifications = (data: any): Notification[] =>
|
2021-10-01 07:24:25 +00:00
|
|
|
etjanst(data).map(notification).sort(notificationsSort)
|