decide.nolog.cz/app/serializers/poll.js

30 lines
741 B
JavaScript
Raw Normal View History

import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
2018-12-29 01:27:37 +01:00
import { isEmpty } from '@ember/utils';
import ApplicationSerializer from './application';
2014-10-30 21:44:22 +01:00
export default class PollSerializer extends ApplicationSerializer.extend(
EmbeddedRecordsMixin,
) {
attrs = {
users: {
deserialize: 'records',
},
};
2015-10-25 16:46:11 +01:00
legacySupport(resourceHash) {
// croodle <= 0.3.0
2016-01-28 23:48:14 +01:00
// property 'type' of answers was named 'id'
2015-10-25 16:46:11 +01:00
if (
resourceHash.answers.length > 0 &&
2018-12-29 01:27:37 +01:00
!isEmpty(resourceHash.answers[0].id)
2015-10-25 16:46:11 +01:00
) {
resourceHash.answers.forEach((answer, index) => {
resourceHash.answers[index].type = answer.id;
delete resourceHash.answers[index].id;
});
}
return resourceHash;
}
}