Skip to content

Instantly share code, notes, and snippets.

@jeznag
Created May 17, 2015 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeznag/f5e06c19e2046b910d7f to your computer and use it in GitHub Desktop.
Save jeznag/f5e06c19e2046b910d7f to your computer and use it in GitHub Desktop.
Person deserializer
import DS from 'ember-data';
import config from '../config/environment';
var counter = 1;
export default DS.RESTSerializer.extend({
extractSingle: function(store, type, payload, id) {
var people = payload.results.people;
payload = {
people: people
};
return this._super(store, type, payload, id);
},
extractArray: function(store, type, payload) {
if (config.environment !== 'production') {
//using Mirage
return this._super(store, type, payload);
}
var people = payload.results.people;
payload = {
people: people
};
return this._super(store, type, payload);
},
normalizeHash: {
// Next, normalize individual people, which (after `extract`)
// are now located under `people`
people: function(hash) {
if (config.environment !== 'production') {
//using Mirage - no normalisation necessary
return;
}
//fix variable names as the model uses fullName and photoURL rather than name/photo
hash.fullName = hash.name;
hash.photoURL = hash.photo;
hash.id = counter;
counter++;
delete hash.name;
delete hash.photo;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment