2020-01-18 10:13:50 +01:00
|
|
|
import classic from 'ember-classic-decorator';
|
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';
|
2015-10-25 16:46:11 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@classic
|
|
|
|
export default class UserSerializer extends ApplicationSerializer {
|
2016-01-31 14:32:32 +01:00
|
|
|
legacySupport(resourceHash) {
|
2015-10-25 16:46:11 +01:00
|
|
|
/*
|
|
|
|
* Croodle <= 0.3.0:
|
|
|
|
* * for answer type "freetext":
|
|
|
|
* selections where a string containing label
|
|
|
|
* * all other answer types ("YesNo", "YesNoMaybe"):
|
|
|
|
* selections where stored as child object of "value" property
|
|
|
|
* and selection property "type" where named "id"
|
|
|
|
*/
|
2018-12-29 01:27:37 +01:00
|
|
|
if (!isEmpty(resourceHash.selections[0].value)) {
|
2023-10-15 20:37:03 +02:00
|
|
|
resourceHash.selections.forEach(function (selection, index) {
|
2015-10-25 16:46:11 +01:00
|
|
|
if (typeof selection.value === 'string') {
|
|
|
|
resourceHash.selections[index] = {
|
2023-10-15 20:37:03 +02:00
|
|
|
label: selection.value,
|
2015-10-25 16:46:11 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
resourceHash.selections[index] = {
|
|
|
|
icon: selection.value.icon,
|
|
|
|
label: selection.value.label,
|
|
|
|
labelTranslation: selection.value.labelTranslation,
|
2023-10-15 20:37:03 +02:00
|
|
|
type: selection.value.id,
|
2015-10-25 16:46:11 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-01-31 14:32:32 +01:00
|
|
|
|
2015-10-25 16:46:11 +01:00
|
|
|
return resourceHash;
|
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|