2020-01-08 15:58:52 +01:00
|
|
|
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
|
2018-12-29 01:27:37 +01:00
|
|
|
import { isEmpty } from '@ember/utils';
|
2020-01-18 10:13:50 +01:00
|
|
|
import ApplicationSerializer from './application';
|
2014-10-30 21:44:22 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
export default class PollSerializer extends ApplicationSerializer.extend(
|
2023-10-17 10:44:45 +02:00
|
|
|
EmbeddedRecordsMixin,
|
2023-10-15 20:37:03 +02:00
|
|
|
) {
|
2020-01-18 10:13:50 +01:00
|
|
|
attrs = {
|
2015-01-20 22:47:04 +01:00
|
|
|
users: {
|
2023-10-15 20:37:03 +02:00
|
|
|
deserialize: 'records',
|
|
|
|
},
|
2020-01-18 10:13:50 +01:00
|
|
|
};
|
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;
|
2014-09-28 14:55:40 +02:00
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|