1
1
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application' ;
2
2
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest' ;
3
3
import { getProperties , setProperties } from '@ember/object' ;
4
+ import { isBlank } from '@ember/utils' ;
4
5
5
6
export default class WaypointSerializer extends ApplicationSerializer . extend ( EmbeddedRecordsMixin ) {
6
7
/**
@@ -11,6 +12,7 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
11
12
get attrs ( ) {
12
13
return {
13
14
place : { embedded : 'always' } ,
15
+ customer : { embedded : 'always' } ,
14
16
tracking_number : { embedded : 'always' } ,
15
17
} ;
16
18
}
@@ -55,4 +57,26 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
55
57
56
58
return super . normalize ( model , hash , prop ) ;
57
59
}
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
+ }
58
82
}
0 commit comments