@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
130 lines (114 loc) • 3.75 kB
JavaScript
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
export default class EntityModel extends Model {
/** @ids */
public_id;
internal_id;
_import_id;
payload_uuid;
company_uuid;
customer_uuid;
supplier_uuid;
driver_assigned_uuid;
tracking_number_uuid;
destination_uuid;
photo_uuid;
/** @relationships */
payload;
customer;
supplier;
driver;
trackingNumber;
destination;
photo;
/** @attributes */
name;
type;
description;
photo_url;
currency;
barcode;
tracking;
qr_code;
weight;
weight_unit;
length;
width;
height;
dimensions_unit;
declared_value;
sku;
price;
sale_price;
slug;
meta;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
get dimensions() {
return this.length + 'x' + this.width + 'x' + this.height + ' ' + this.dimensions_unit;
}
get displayLength() {
return this.length + this.dimensions_unit;
}
get displayWidth() {
return this.width + this.dimensions_unit;
}
get displayHeight() {
return this.height + this.dimensions_unit;
}
get displayWeight() {
return this.weight + this.weight_unit;
}
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, 'PPP p');
}
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, 'PPP p');
}
get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}
}