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
1 change: 1 addition & 0 deletions addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class DriverModel extends Model {
@attr('raw') meta;

/** @dates */
@attr('date') license_expiry;
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;
Expand Down
2 changes: 1 addition & 1 deletion addon/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class OrderModel extends Model {

/** @relationships */
@belongsTo('company') company;
@belongsTo('order-config') order_config;
@belongsTo('order-config', { async: false }) order_config;
@belongsTo('customer', { polymorphic: true, async: false }) customer;
@belongsTo('facilitator', { polymorphic: true, async: false }) facilitator;
@belongsTo('transaction', { async: false }) transaction;
Expand Down
10 changes: 10 additions & 0 deletions addon/serializers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
*/
serialize(snapshot, options) {
const json = super.serialize(snapshot, options);
const selectedOrderConfigUuid = snapshot.attr('order_config_uuid');
const selectedType = snapshot.attr('type');
const unshiftAttributes = [
'order_config',
'driver_name',
Expand All @@ -59,6 +61,14 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
delete json[attr];
});

if (!isBlank(selectedOrderConfigUuid)) {
json.order_config_uuid = selectedOrderConfigUuid;
}

if (!isBlank(selectedType)) {
json.type = selectedType;
}

return json;
}

Expand Down
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.32",
"version": "0.1.33",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/models/order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ module('Unit | Model | order', function (hooks) {
let model = store.createRecord('order', {});
assert.ok(model);
});

test('order config is embedded synchronously', function (assert) {
let store = this.owner.lookup('service:store');
let relationship = store.modelFor('order').relationshipsByName.get('order_config');

assert.strictEqual(relationship.options.async, false);
});
});
35 changes: 35 additions & 0 deletions tests/unit/serializers/order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,39 @@ module('Unit | Serializer | order', function (hooks) {

assert.ok(serializedRecord);
});

test('selected order config scalar fields win over a stale relationship snapshot', function (assert) {
let store = this.owner.lookup('service:store');
let transport = store.push({
data: {
type: 'order-config',
id: 'transport-config-uuid',
attributes: {
key: 'transport',
name: 'Transport',
},
},
});
let haulage = store.push({
data: {
type: 'order-config',
id: 'haulage-config-uuid',
attributes: {
key: 'haulage',
name: 'Haulage',
},
},
});
let record = store.createRecord('order', {
order_config: transport,
order_config_uuid: haulage.id,
type: haulage.key,
});

let serializedRecord = record.serialize();

assert.strictEqual(serializedRecord.order_config_uuid, haulage.id);
assert.strictEqual(serializedRecord.type, haulage.key);
assert.notOk(serializedRecord.order_config);
});
});
Loading