open-nomad/ui/mirage/serializers/application.js
Phil Renaud 311a6d82c9
Importing string methods directly from @ember/string (#12499)
* Capitalize methods

* Let ESLint yell at us again

* Dasherize
2022-04-07 15:51:41 -04:00

26 lines
711 B
JavaScript

import { camelize, capitalize } from '@ember/string';
import { RestSerializer } from 'ember-cli-mirage';
const keyCase = (str) =>
str === 'id' ? 'ID' : capitalize(camelize(str)).replace(/Id/g, 'ID');
export default RestSerializer.extend({
serialize() {
const json = RestSerializer.prototype.serialize.apply(this, arguments);
const keys = Object.keys(json);
if (keys.length === 1) {
return json[keys[0]];
} else {
return json;
}
},
keyForModel: keyCase,
keyForForeignKey: (str) => `${keyCase(str)}ID`,
keyForCollection: keyCase,
keyForAttribute: keyCase,
keyForRelationship: keyCase,
keyForRelationshipIds: keyCase,
keyForEmbeddedRelationship: keyCase,
});