vault/ui/app/serializers/clients/config.js
Angel Garbarino 4fd4a0693d
Remove readOnly attrs from Clients Count Config Serializer (#21391)
* octanify and add serialize false to readonly attrs

* alphabetize

* stuff

* adds back payload.data check in normalizeResponse method of clients config serializer

* test things

* fix

* clean up

* Update ui/app/serializers/clients/config.js

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>

---------

Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2023-06-22 01:28:59 +00:00

44 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from '../application';
export default class ClientsConfigSerializer extends ApplicationSerializer {
// these attrs are readOnly
attrs = {
billingStartTimestamp: { serialize: false },
minimumRetentionMonths: { serialize: false },
reportingEnabled: { serialize: false },
};
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
if (!payload.data) {
return super.normalizeResponse(...arguments);
}
const normalizedPayload = {
id: payload.id,
data: {
...payload.data,
enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off',
},
};
return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType);
}
serialize() {
const json = super.serialize(...arguments);
if (json.enabled === 'On' || json.enabled === 'Off') {
const oldEnabled = json.enabled;
json.enabled = oldEnabled === 'On' ? 'enable' : 'disable';
}
json.retention_months = parseInt(json.retention_months, 10);
if (isNaN(json.retention_months)) {
throw new Error('Invalid number value');
}
delete json.queries_available;
return json;
}
}