@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
61 lines (53 loc) • 1.73 kB
JavaScript
import Model, { attr } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
/**
* Abstract base model for resources a device can be attached to.
* Concrete types: attachable-vehicle, attachable-asset.
*/
export default class AttachableModel extends Model {
/** @ids */
uuid;
public_id;
company_uuid;
/** @attributes */
name;
display_name;
type;
status;
photo_url;
avatar_url;
online;
is_online;
location;
speed;
heading;
altitude;
meta;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
get displayName() {
return this.display_name || this.name || this.public_id;
}
get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDistanceToNow(this.updated_at);
}
get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}
get updatedAtShort() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'dd, MMM');
}
}