Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions addon/models/maintenance-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ export default class MaintenanceScheduleModel extends Model {
@attr('string') uuid;
@attr('string') public_id;
@attr('string') company_uuid;
@attr('string') subject_uuid;
@attr('string') subject_type;
@attr('string') default_assignee_uuid;
@attr('string') default_assignee_type;

/** @polymorphic relationships */
@belongsTo('maintenance-subject', { polymorphic: true, async: false }) subject;
@belongsTo('facilitator', { polymorphic: true, async: false }) default_assignee;

/** @computed names — server-side convenience fields (read-only) */
@attr('string') subject_name;
@attr('string') default_assignee_name;
Expand Down
24 changes: 23 additions & 1 deletion addon/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class OrderModel extends Model {
@attr('string') purchase_rate_uuid;
@attr('string') tracking_number_uuid;
@attr('string') driver_assigned_uuid;
@attr('string') vehicle_assigned_uuid;
@attr('string') manifest_uuid;
@attr('string') service_quote_uuid;
@attr('string') order_config_uuid;
Expand Down Expand Up @@ -58,6 +59,7 @@ export default class OrderModel extends Model {
@alias('payload.entitiesByDestination') entitiesByDestination;
@alias('payload.isMultiDrop') isMultiDrop;
@alias('payload.isMultiDrop') isMultiDropOrder;
@alias('payload.hasIntermediateWaypoints') hasIntermediateWaypoints;

/** @attributes */
@attr('string') tracking;
Expand All @@ -76,10 +78,15 @@ export default class OrderModel extends Model {
@attr('string') notes;
@attr('string') type;
@attr('string') status;
@attr('string') latest_status;
@attr('string') latest_status_code;
@attr('number') adhoc_distance;
@attr('number') distance;
@attr('number') time;
@attr('number') total_entities;
@attr('number') transaction_amount;
@attr('boolean') has_driver_assigned;
@attr('boolean') is_scheduled;
@attr('boolean') pod_required;
@attr('boolean') dispatched;
@attr('boolean') started;
Expand Down Expand Up @@ -466,10 +473,25 @@ export default class OrderModel extends Model {
async loadPayload(options = {}) {
const owner = getOwner(this);
const store = owner.lookup('service:store');
if (shouldNotLoadRelation(this, 'payload')) {
if (isBlank(this.payload_uuid)) {
return;
}

const existingPayload = this.payload;
const isLightweightIndexOrder = this.meta?._index_resource === true;
const hasLoadedWaypointCollection = typeof existingPayload?.waypoints?.toArray === 'function' || isArray(existingPayload?.waypoints);
const indexedWaypointCount = Number(existingPayload?.waypoints_count ?? 0);
const loadedWaypointCount = Number(existingPayload?.waypoints?.length ?? 0);
const needsWaypointUpgrade = indexedWaypointCount > 0 && loadedWaypointCount === 0;

if (existingPayload && hasLoadedWaypointCollection && !needsWaypointUpgrade) {
return existingPayload;
}

if (existingPayload && !hasLoadedWaypointCollection && !isLightweightIndexOrder) {
return existingPayload;
}

const payload = await store.queryRecord(
'payload',
{
Expand Down
17 changes: 14 additions & 3 deletions addon/models/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ export default class PayloadModel extends Model {
@hasMany('entity', { async: false }) entities;

/** @attributes */
@attr('string') meta;
@attr('raw') meta;
@attr('string') cod_amount;
@attr('string') cod_currency;
@attr('string') cod_payment_method;
@attr('string') payment_method;
@attr('string') type;
@attr('number') entities_count;
@attr('number') waypoints_count;
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;
Expand All @@ -35,6 +38,14 @@ export default class PayloadModel extends Model {
@notEmpty('dropoff_uuid') hasDropoff;
@notEmpty('return_uuid') hasReturn;

@computed('waypoints.[]') get hasIntermediateWaypoints() {
return this.waypoints.length > 0;
}

@computed('waypoints_count') get waypoint_count() {
return this.waypoints_count;
}

@computed('waypoints.[]', 'pickup_uuid', 'dropoff_uuid') get isMultiDrop() {
return this.waypoints.length > 0 && !this.pickup_uuid && !this.dropoff_uuid;
}
Expand Down Expand Up @@ -109,12 +120,12 @@ export default class PayloadModel extends Model {

// eslint-disable-next-line ember/use-brace-expansion
@computed('{dropoff,pickup,waypoints}', 'waypoints.[]') get places() {
return [this.pickup, ...this.waypoints.toArray(), this.pickup].filter(Boolean);
return [this.pickup, ...this.waypoints.toArray(), this.dropoff].filter(Boolean);
}

// eslint-disable-next-line ember/use-brace-expansion
@computed('waypoints.@each.place', 'waypoints.[]') get waypointPlaces() {
return this.waypoints.toArray().map((wp) => wp.place);
return this.waypoints.toArray().map((wp) => wp.place ?? wp);
}

@computed('{dropoff,pickup,waypoints}', 'waypoints.[]') get payloadCoordinates() {
Expand Down
50 changes: 50 additions & 0 deletions addon/models/recurring-order-schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default class RecurringOrderScheduleModel extends Model {
@attr('string') public_id;
@attr('string') uuid;
@attr('string') name;
@attr('string') description;
@attr('string') status;
@attr('string') timezone;
@attr('date') starts_at;
@attr('date') ends_at;
@attr('string') rrule;
@attr('date') last_materialized_at;
@attr('date') materialization_horizon;
@attr('string') customer_uuid;
@attr('string') customer_type;
@attr('string') facilitator_uuid;
@attr('string') facilitator_type;
@attr('string') order_config_uuid;
@attr('string') driver_assigned_uuid;
@attr('string') vehicle_assigned_uuid;
@attr('string') service_rate_uuid;
@attr('raw') template_order_meta;
@attr('raw') template_payload;
@attr('raw') template_entities;
@attr('raw') meta;
@attr('raw') upcoming_occurrences;
@attr('date') next_occurrence_at;
@attr('date') created_at;
@attr('date') updated_at;

@belongsTo('customer', { polymorphic: true, async: false }) customer;
@belongsTo('facilitator', { polymorphic: true, async: false }) facilitator;
@belongsTo('order-config', { async: false }) order_config;
@belongsTo('driver', { async: false }) driver_assigned;
@belongsTo('vehicle', { async: false }) vehicle_assigned;
@belongsTo('service-rate', { async: false }) service_rate;

get isActive() {
return this.status === 'active';
}

get isPaused() {
return this.status === 'paused';
}

get isCanceled() {
return this.status === 'canceled';
}
}
1 change: 1 addition & 0 deletions addon/models/waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class WaypointModel extends PlaceModel {
@attr('string') status_code;
@attr('string') type;
@attr('number') order;
@attr('boolean') complete;
// Orchestrator time windows
@attr('date') time_window_start;
@attr('date') time_window_end;
Expand Down
4 changes: 0 additions & 4 deletions addon/serializers/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ export default class EntitySerializer extends ApplicationSerializer.extend(Embed
if (isPolymorphicTypeBlank) {
key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;

if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}

if (!belongsTo) {
json[key + '_type'] = null;
} else {
Expand Down
3 changes: 0 additions & 3 deletions addon/serializers/maintenance-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export default class MaintenanceScheduleSerializer extends ApplicationSerializer
json[key + '_type'] = null;
} else {
let type = belongsTo.modelName;
if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}
// Strip abstract subtype prefixes so the server receives the bare model type
// e.g. 'facilitator-vendor' -> 'vendor', 'maintenance-subject-vehicle' -> 'vehicle'
if (typeof type === 'string') {
Expand Down
3 changes: 0 additions & 3 deletions addon/serializers/maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ export default class MaintenanceSerializer extends ApplicationSerializer.extend(
json[key + '_type'] = null;
} else {
let type = belongsTo.modelName;
if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}
// Strip abstract subtype prefixes so the server receives the bare model type
// e.g. 'facilitator-vendor' -> 'vendor', 'maintenance-subject-vehicle' -> 'vehicle'
if (typeof type === 'string') {
Expand Down
3 changes: 0 additions & 3 deletions addon/serializers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
json[key + '_type'] = null;
} else {
let type = belongsTo.modelName;
if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}
// Strip abstract subtype prefixes so the server receives the bare model type
// e.g. 'facilitator-vendor' -> 'vendor', 'customer-contact' -> 'contact'
if (typeof type === 'string') {
Expand Down
4 changes: 0 additions & 4 deletions addon/serializers/waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
if (isPolymorphicTypeBlank) {
key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;

if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}

// hotfix polymprohpic model types that do not exists as models like `customer-contact` `customer-vendor` should be `contact` or `vendor`
if (typeof type === 'string') {
if (type.startsWith('customer-')) {
Expand Down
3 changes: 0 additions & 3 deletions addon/serializers/work-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export default class WorkOrderSerializer extends ApplicationSerializer.extend(Em
json[key + '_type'] = null;
} else {
let type = belongsTo.modelName;
if (!isBlank(belongsTo.attr(`${key}_type`))) {
type = belongsTo.attr(`${key}_type`);
}
// Strip abstract subtype prefixes so the server receives the bare model type
// e.g. 'facilitator-vendor' -> 'vendor', 'maintenance-subject-vehicle' -> 'vehicle'
if (typeof type === 'string') {
Expand Down
1 change: 1 addition & 0 deletions app/models/recurring-order-schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/fleetops-data/models/recurring-order-schedule';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-data",
"version": "0.1.30",
"version": "0.1.31",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
Loading