Skip to content

Commit

Permalink
Merge pull request #30 from fleetbase/dev-v0.1.12
Browse files Browse the repository at this point in the history
v0.1.12
  • Loading branch information
roncodes authored Mar 11, 2024
2 parents 93d01b9 + 75a116a commit b5ba2a3
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 17 deletions.
3 changes: 2 additions & 1 deletion addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class DriverModel extends Model {
@attr('string') drivers_license_number;
@attr('string', {
defaultValue: get(config, 'defaultValues.driverAvatar'),
}) avatar_url;
})
avatar_url;
@attr('string') avatar_value;
@attr('point') location;
@attr('number') heading;
Expand Down
3 changes: 2 additions & 1 deletion addon/models/order-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export default class OrderConfigModel extends Model {
@attr('string') key;
@attr('string') status;
@attr('string') version;
@attr('string') type;
@attr('boolean', { defaultValue: false }) core_service;
@attr('array') tags;
@attr('object') flow;
@attr('array') entities;
@attr('object') flow;
@attr('object') meta;

/** @computed */
Expand Down
41 changes: 29 additions & 12 deletions addon/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isArray } from '@ember/array';
import { isBlank } from '@ember/utils';
import { getOwner } from '@ember/application';
import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
import groupBy from '@fleetbase/ember-core/utils/macros/group-by';
import isNotModel from '@fleetbase/ember-core/utils/is-not-model';

export default class OrderModel extends Model {
Expand All @@ -23,12 +22,14 @@ export default class OrderModel extends Model {
@attr('string') tracking_number_uuid;
@attr('string') driver_assigned_uuid;
@attr('string') service_quote_uuid;
@attr('string') order_config_uuid;
@attr('string') payload_id;
@attr('string') purchase_rate_id;
@attr('string') driver_id;

/** @relationships */
@belongsTo('company') company;
@belongsTo('order-config') order_config;
@belongsTo('customer', { polymorphic: true, async: false }) customer;
@belongsTo('facilitator', { polymorphic: true, async: false }) facilitator;
@belongsTo('transaction', { async: false }) transaction;
Expand All @@ -37,10 +38,10 @@ export default class OrderModel extends Model {
@belongsTo('route', { async: false }) route;
@belongsTo('purchase-rate', { async: false }) purchase_rate;
@belongsTo('tracking-number', { async: false }) tracking_number;
@belongsTo('order-config', { async: false }) order_config;
@hasMany('tracking-status', { async: false }) tracking_statuses;
@hasMany('comment', { async: false }) comments;
@hasMany('file', { async: false }) files;
@hasMany('custom-field-value', { async: false }) custom_field_values;

/** @aliases */
@alias('driver_assigned') driver;
Expand Down Expand Up @@ -101,8 +102,6 @@ export default class OrderModel extends Model {
@not('hasPayload') missing_payload;
@bool('dispatched') isDispatched;
@not('dispatched') isNotDispatched;
@equal('type', 'storefront') isStorefrontOrder;
@groupBy('order_config.meta.fields', 'group') groupedMetaFields;

@computed('payload.{pickup.name,current_waypoint_uui,waypoints.@each.name}')
get pickupName() {
Expand Down Expand Up @@ -411,6 +410,26 @@ export default class OrderModel extends Model {
return this;
}

async persistProperty(key, value, options = {}) {
return this.persistProperties({ [key]: value }, options);
}

async persistProperties(properties = {}, options = {}) {
const owner = getOwner(this);
const fetch = owner.lookup('service:fetch');

this.setProperties(properties);
if (typeof options.onBefore === 'function') {
options.onBefore(this);
}

return fetch.put(`orders/${this.id}`, properties, { normalizeToEmberData: true, normalizeModelType: 'order' }).then((order) => {
if (typeof options.onAfter === 'function') {
options.onAfter(order);
}
});
}

async loadPayload(options = {}) {
const owner = getOwner(this);
const store = owner.lookup('service:store');
Expand Down Expand Up @@ -465,18 +484,16 @@ export default class OrderModel extends Model {

async loadOrderConfig(options = {}) {
const owner = getOwner(this);
const fetch = owner.lookup('service:fetch');
const store = owner.lookup('service:store');

if (!isBlank(this.order_config)) {
if (!this.order_config_uuid || !isBlank(this.order_config)) {
return;
}

return fetch
.get('fleet-ops/order-configs/get-installed', { key: this.type ?? 'default', single: true }, { normalizeToEmberData: true, normalizeModelType: 'order-config', ...options })
.then((orderConfig) => {
this.set('order_config', orderConfig);
return orderConfig;
});
return store.findRecord('order-config', this.order_config_uuid, options).then((orderConfig) => {
this.set('order_config', orderConfig);
return orderConfig;
});
}

async loadDriver(options = {}) {
Expand Down
3 changes: 2 additions & 1 deletion addon/models/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default class PlaceModel extends Model {
@attr('string') type;
@attr('string', {
defaultValue: get(config, 'defaultValues.placeAvatar'),
}) avatar_url;
})
avatar_url;
@attr('string') avatar_value;
@attr('string') address;
@attr('string') address_html;
Expand Down
4 changes: 4 additions & 0 deletions addon/serializers/order-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class OrderConfigSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {}
3 changes: 2 additions & 1 deletion addon/serializers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
*/
get attrs() {
return {
order_config: { embedded: 'always' },
payload: { embedded: 'always' },
driver_assigned: { embedded: 'always' },
facilitator: { embedded: 'always' },
Expand All @@ -21,6 +22,7 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
tracking_statuses: { embedded: 'always' },
files: { embedded: 'always' },
comments: { embedded: 'always' },
custom_field_values: { embedded: 'always' },
};
}

Expand All @@ -35,7 +37,6 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
const json = super.serialize(snapshot, options);
const unshiftAttributes = [
'order_config',
'order_config_uuid',
'driver_name',
'tracking',
'total_entities',
Expand Down
1 change: 1 addition & 0 deletions app/serializers/order-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/fleetops-data/serializers/order-config';
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.11",
"version": "0.1.12",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/serializers/order-config-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { module, test } from 'qunit';

import { setupTest } from 'dummy/tests/helpers';

module('Unit | Serializer | order config', function (hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('order-config');

assert.ok(serializer);
});

test('it serializes records', function (assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('order-config', {});

let serializedRecord = record.serialize();

assert.ok(serializedRecord);
});
});

0 comments on commit b5ba2a3

Please sign in to comment.