Skip to content

Commit

Permalink
Refactor serializer to native classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmanuel committed Jul 30, 2023
1 parent da62b41 commit d7c8f54
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions addon/serializers/serializer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import JSONAPISerializer from '@ember-data/serializer/json-api';

export default JSONAPISerializer.extend({
export default class Serializer extends JSONAPISerializer {
shouldSerializeHasMany() {
return true;
},
}

serializeBelongsTo() {
this._fixSerializeBelongsTo(...arguments);
},

serializeHasMany() {
this._fixSerializeHasMany(...arguments);
},
}

_fixSerializeBelongsTo(snapshot, json, relationship) {
let key = relationship.key;
Expand Down Expand Up @@ -43,7 +39,11 @@ export default JSONAPISerializer.extend({
json.relationships[payloadKey] = { data };
}
}
},
}

serializeHasMany() {
this._fixSerializeHasMany(...arguments);
}

_fixSerializeHasMany(snapshot, json, relationship) {
let key = relationship.key;
Expand All @@ -66,7 +66,7 @@ export default JSONAPISerializer.extend({
let data = new Array(nonNewHasMany.length);

for (let i = 0; i < nonNewHasMany.length; i++) {
let item = hasMany[i];
let item = nonNewHasMany[i];
let payloadType = this.payloadKeyFromModelName(item.modelName);

data[i] = {
Expand All @@ -78,5 +78,5 @@ export default JSONAPISerializer.extend({
json.relationships[payloadKey] = { data };
}
}
},
});
}
}

0 comments on commit d7c8f54

Please sign in to comment.