@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
80 lines (69 loc) • 2.14 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 ServiceRateFeeModel extends Model {
/** @ids */
service_rate_uuid;
/** @attributes */
distance;
distance_unit;
unit;
fee;
currency;
min;
max;
/** @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,
distance: this.distance,
distance_unit: this.distance_unit,
min: this.min,
max: this.max,
unit: this.unit,
fee: this.fee,
currency: this.currency,
};
}
}