Skip to content
Open
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
3 changes: 3 additions & 0 deletions addon/serializers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ 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
26 changes: 15 additions & 11 deletions addon/serializers/waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,30 @@ export default class WaypointSerializer extends ApplicationSerializer.extend(Emb
serializePolymorphicType(snapshot, json, relationship) {
let key = relationship.key;
let belongsTo = snapshot.belongsTo(key);
let type = belongsTo.modelName;

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

// 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-')) {
type = type.replace('customer-', '');
}
if (type.startsWith('facilitator-')) {
type = type.replace('facilitator-', '');
}
}

if (!belongsTo) {
json[key + '_type'] = null;
} else {
let type = belongsTo.modelName;
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-')) {
type = type.replace('customer-', '');
}
if (type.startsWith('facilitator-')) {
type = type.replace('facilitator-', '');
}
}

json[key + '_type'] = `fleet-ops:${type}`;
}
}
Expand Down
Loading