@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
140 lines (122 loc) • 4.27 kB
JavaScript
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
export default class SensorModel extends Model {
/** @ids */
public_id;
company_uuid;
telematic_uuid;
device_uuid;
warranty_uuid;
sensorable_type;
sensorable_uuid;
photo_uuid;
/** @relationships */
telematic;
device;
warranty;
custom_field_values;
/** @attributes */
name;
photo_url;
internal_id;
type;
serial_number;
imei;
imsi;
firmware_version;
unit;
threshold_status;
min_threshold;
max_threshold;
threshold_inclusive;
is_active;
last_value;
report_frequency_sec;
last_position;
calibration;
meta;
slug;
status;
/** @dates */
last_reading_at;
deleted_at;
created_at;
updated_at;
/** @computed */
get displayName() {
return this.name || this.serial_number || this.internal_id || this.imei || 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');
}
get createdAgo() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDistanceToNow(this.created_at);
}
get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}
get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}
get deletedAgo() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDistanceToNow(this.deleted_at);
}
get deletedAt() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'yyyy-MM-dd HH:mm');
}
get deletedAtShort() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'dd, MMM');
}
get lastReadingAgo() {
if (!isValidDate(this.last_reading_at)) {
return null;
}
return formatDistanceToNow(this.last_reading_at);
}
get lastReadingAt() {
if (!isValidDate(this.last_reading_at)) {
return null;
}
return formatDate(this.last_reading_at, 'yyyy-MM-dd HH:mm');
}
get lastReadingAtShort() {
if (!isValidDate(this.last_reading_at)) {
return null;
}
return formatDate(this.last_reading_at, 'dd, MMM');
}
}