@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
84 lines (73 loc) • 2.3 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';
export default class ServiceRateParcelFeeModel extends Model {
/** @ids */
service_rate_uuid;
/** @attributes */
size;
length;
width;
height;
dimensions_unit;
weight;
weight_unit;
fee;
currency;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
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');
}
/** @methods */
toJSON() {
return {
service_rate_uuid: this.service_rate_uuid,
size: this.size,
length: this.length,
width: this.width,
height: this.height,
dimensions_unit: this.dimensions_unit,
weight: this.weight,
weight_unit: this.weight_unit,
fee: this.fee,
currency: this.currency,
};
}
}