@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
145 lines (130 loc) • 4.5 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 AssetModel extends Model {
/** @ids */
public_id;
company_uuid;
category_uuid;
vendor_uuid;
warranty_uuid;
telematic_uuid;
assigned_to_uuid;
assigned_to_type;
operator_uuid;
operator_type;
current_place_uuid;
photo_uuid;
/** @relationships */
category;
vendor;
warranty;
telematic;
current_place;
photo;
devices;
equipments;
maintenances;
sensors;
parts;
custom_field_values;
/** @attributes */
name;
description;
code;
type;
location;
speed;
heading;
altitude;
status;
usage_type;
vin;
plate_number;
make;
model;
year;
color;
serial_number;
measurement_system;
odometer;
odometer_unit;
transmission;
fuel_volume_unit;
fuel_Type;
ownership_type;
engine_hours;
gvw;
capacity;
specs;
attributes;
notes;
slug;
photo_url;
display_name;
category_name;
vendor_name;
warranty_name;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
get yearMakeModel() {
return [this.year, this.make, this.model].filter(Boolean).join(' ');
}
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');
}
}