mirror of
https://github.com/fleetbase/fleetbase.git
synced 2026-01-04 21:37:08 +00:00
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import Model, { attr } from '@ember-data/model';
|
|
import { computed } from '@ember/object';
|
|
import { format, formatDistanceToNow } from 'date-fns';
|
|
|
|
export default class NotificationModel extends Model {
|
|
@attr('string') notifiable_id;
|
|
@attr('string') notifiable_type;
|
|
|
|
/** @attributes */
|
|
@attr('string') type;
|
|
@attr('raw') data;
|
|
@attr('raw') meta;
|
|
|
|
/** @dates */
|
|
@attr('date') read_at;
|
|
@attr('date') created_at;
|
|
|
|
/** @computed */
|
|
@computed('created_at') get createdAgo() {
|
|
return formatDistanceToNow(this.created_at);
|
|
}
|
|
|
|
@computed('created_at') get createdAt() {
|
|
return format(this.created_at, 'PPP p');
|
|
}
|
|
|
|
@computed('read_at') get readAt() {
|
|
return format(this.read_at, 'PPP p');
|
|
}
|
|
|
|
@computed('read_at') get isRead() {
|
|
return this.read_at instanceof Date;
|
|
}
|
|
|
|
@computed('read_at') get read() {
|
|
return this.read_at instanceof Date;
|
|
}
|
|
|
|
@computed('isRead') get unread() {
|
|
return !this.get('isRead');
|
|
}
|
|
|
|
/** @actions */
|
|
markAsRead() {
|
|
if (this.isRead) {
|
|
return;
|
|
}
|
|
|
|
this.set('read_at', new Date());
|
|
return this.save();
|
|
}
|
|
}
|