@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
96 lines (79 loc) • 2.75 kB
JavaScript
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate } from 'date-fns';
/**
* ManifestStop model
*
* Represents a single physical stop within a Manifest. Each stop corresponds
* to one Order (or one waypoint within a multi-waypoint order) and carries
* a direct FK to the Place it represents for fast map rendering and geofence
* arrival detection in the Navigator app.
*
* Status lifecycle: pending → arrived → completed | skipped
*/
export default class ManifestStopModel extends Model {
/** @ids */
public_id;
manifest_uuid;
order_uuid;
place_uuid;
waypoint_uuid;
/** @relationships */
manifest;
order;
place;
/** @attributes */
sequence;
status;
notes;
/** @timing */
estimated_arrival;
actual_arrival;
/** @distance from previous stop (metres) */
distance_from_prev_m;
/** @meta */
meta;
/** @dates */
created_at;
updated_at;
/** @computed */
get isPending() {
return this.status === 'pending';
}
get isArrived() {
return this.status === 'arrived';
}
get isCompleted() {
return this.status === 'completed';
}
get isSkipped() {
return this.status === 'skipped';
}
get statusLabel() {
const labels = {
pending: 'Pending',
arrived: 'Arrived',
completed: 'Completed',
skipped: 'Skipped',
};
return labels[this.status] ?? this.status;
}
get estimatedArrivalFormatted() {
if (!isValidDate(this.estimated_arrival)) {
return null;
}
return formatDate(this.estimated_arrival, 'HH:mm');
}
get actualArrivalFormatted() {
if (!isValidDate(this.actual_arrival)) {
return null;
}
return formatDate(this.actual_arrival, 'HH:mm');
}
get distanceFromPrevKm() {
return this.distance_from_prev_m ? (this.distance_from_prev_m / 1000).toFixed(1) : null;
}
get stopLabel() {
return `Stop ${this.sequence}`;
}
}