Skip to content

Commit 82418b7

Browse files
authored
Merge pull request #33 from fleetbase/dev-v0.1.15
dev-v0.1.15
2 parents 56b8ae5 + f5fa26c commit 82418b7

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

addon/models/order.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default class OrderModel extends Model {
3535
@belongsTo('transaction', { async: false }) transaction;
3636
@belongsTo('payload', { async: false }) payload;
3737
@belongsTo('driver', { async: false, inverse: 'jobs' }) driver_assigned;
38+
@belongsTo('vehicle', { async: false }) vehicle_assigned;
3839
@belongsTo('route', { async: false }) route;
3940
@belongsTo('purchase-rate', { async: false }) purchase_rate;
4041
@belongsTo('tracking-number', { async: false }) tracking_number;
@@ -45,6 +46,7 @@ export default class OrderModel extends Model {
4546

4647
/** @aliases */
4748
@alias('driver_assigned') driver;
49+
@alias('vehicle_assigned') vehicle;
4850

4951
/** @attributes */
5052
@attr('string') tracking;

addon/models/payload.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class PayloadModel extends Model {
1515
@belongsTo('place', { async: false }) pickup;
1616
@belongsTo('place', { async: false }) dropoff;
1717
@belongsTo('place', { async: false }) return;
18-
@hasMany('waypoint') waypoints;
19-
@hasMany('entity') entities;
18+
@hasMany('waypoint', { async: false }) waypoints;
19+
@hasMany('entity', { async: false }) entities;
2020

2121
/** @attributes */
2222
@attr('string') meta;

addon/models/waypoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ export default class WaypointModel extends PlaceModel {
66
/** @relationships */
77
@belongsTo('place', { async: false }) place;
88
@belongsTo('tracking-number', { async: false }) tracking_number;
9+
@belongsTo('customer', { polymorphic: true, async: false }) customer;
910

1011
/** @attributes */
1112
@attr('string') public_id;
1213
@attr('string') _import_id;
1314
@attr('string') waypoint_uuid;
1415
@attr('string') waypoint_public_id;
1516
@attr('string') tracking_number_uuid;
17+
@attr('string') customer_uuid;
18+
@attr('string') customer_type;
1619
@attr('string') tracking;
1720
@attr('string') status;
1821
@attr('string') status_code;

addon/serializers/order.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
1313
order_config: { embedded: 'always' },
1414
payload: { embedded: 'always' },
1515
driver_assigned: { embedded: 'always' },
16+
vehicle_assigned: { embedded: 'always' },
1617
facilitator: { embedded: 'always' },
1718
customer: { embedded: 'always' },
1819
transaction: { embedded: 'always' },
@@ -78,7 +79,6 @@ export default class OrderSerializer extends ApplicationSerializer.extend(Embedd
7879

7980
// if snapshot already has type filled respect manual input
8081
const isPolymorphicTypeBlank = isBlank(snapshot.attr(key + '_type'));
81-
8282
if (isPolymorphicTypeBlank) {
8383
key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
8484

addon/serializers/waypoint.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
22
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
33
import { getProperties, setProperties } from '@ember/object';
4+
import { isBlank } from '@ember/utils';
45

56
export default class WaypointSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
67
/**
@@ -11,6 +12,7 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
1112
get attrs() {
1213
return {
1314
place: { embedded: 'always' },
15+
customer: { embedded: 'always' },
1416
tracking_number: { embedded: 'always' },
1517
};
1618
}
@@ -55,4 +57,26 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
5557

5658
return super.normalize(model, hash, prop);
5759
}
60+
61+
serializePolymorphicType(snapshot, json, relationship) {
62+
let key = relationship.key;
63+
let belongsTo = snapshot.belongsTo(key);
64+
let type = belongsTo.modelName;
65+
66+
// if snapshot already has type filled respect manual input
67+
const isPolymorphicTypeBlank = isBlank(snapshot.attr(key + '_type'));
68+
if (isPolymorphicTypeBlank) {
69+
key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
70+
71+
if (!isBlank(belongsTo.attr(`${key}_type`))) {
72+
type = belongsTo.attr(`${key}_type`);
73+
}
74+
75+
if (!belongsTo) {
76+
json[key + '_type'] = null;
77+
} else {
78+
json[key + '_type'] = `fleet-ops:${type}`;
79+
}
80+
}
81+
}
5882
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fleetbase/fleetops-data",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
55
"keywords": [
66
"fleetbase-data",

0 commit comments

Comments
 (0)