decide.nolog.cz/app/serializers/user.js
Jeldrik Hanschke c9482786c1
refactor to native ECMAScript classes (#344)
Replaces Ember's old object model by native ECMAScript classes. Mostly automated with ember-native-class-codemod.
2020-01-18 10:13:50 +01:00

35 lines
1.1 KiB
JavaScript

import classic from 'ember-classic-decorator';
import { isEmpty } from '@ember/utils';
import ApplicationSerializer from './application';
@classic
export default class UserSerializer extends ApplicationSerializer {
legacySupport(resourceHash) {
/*
* 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"
*/
if (!isEmpty(resourceHash.selections[0].value)) {
resourceHash.selections.forEach(function(selection, index) {
if (typeof selection.value === 'string') {
resourceHash.selections[index] = {
label: selection.value
};
} else {
resourceHash.selections[index] = {
icon: selection.value.icon,
label: selection.value.label,
labelTranslation: selection.value.labelTranslation,
type: selection.value.id
};
}
});
}
return resourceHash;
}
}