open-vault/ui/app/serializers/control-group.js
Jordan Reimer 52fe56ec87
Eslint prefer-const (#17864)
* adds prefer-const to eslint config and runs fixer

* reverts unintended change
2022-11-09 15:15:31 -08:00

29 lines
858 B
JavaScript

import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
requestEntity: { embedded: 'always' },
authorizations: { embedded: 'always' },
},
normalizeResponse(store, primaryModelClass, payload) {
const entity = payload?.data?.request_entity;
if (Array.isArray(payload.data.authorizations)) {
for (const authorization of payload.data.authorizations) {
authorization.id = authorization.entity_id;
authorization.name = authorization.entity_name;
}
}
if (entity && Object.keys(entity).length === 0) {
payload.data.request_entity = null;
}
return this._super(...arguments);
},
serialize(snapshot) {
return { accessor: snapshot.id };
},
});