@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
112 lines (96 loc) • 3.16 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 ServiceRateFeeModel extends Model {
/** @ids */
uuid;
service_rate_uuid;
service_area_uuid;
zone_uuid;
/** @relationships */
service_area;
zone;
/** @attributes */
label;
priority;
is_fallback;
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, '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 geography_type() {
if (this.selected_geography_type) {
return this.selected_geography_type;
}
if (this.is_fallback) {
return 'fallback';
}
if (this.zone_uuid || this.zone?.id) {
return 'zone';
}
return 'service_area';
}
/** @methods */
toJSON() {
return {
uuid: this.uuid,
service_rate_uuid: this.service_rate_uuid,
service_area_uuid: this.service_area_uuid,
zone_uuid: this.zone_uuid,
label: this.label,
priority: this.priority,
is_fallback: this.is_fallback,
distance: this.distance,
distance_unit: this.distance_unit,
min: this.min,
max: this.max,
unit: this.unit,
fee: this.fee,
currency: this.currency,
};
}
}