2020-10-01 19:37:33 +00:00
|
|
|
import ApplicationSerializer from '../application';
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
2020-10-08 15:23:59 +00:00
|
|
|
if (!payload.data) {
|
|
|
|
// CBS TODO: Remove this if block once API is published
|
|
|
|
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
|
|
}
|
2020-10-01 19:37:33 +00:00
|
|
|
const normalizedPayload = {
|
|
|
|
id: payload.id,
|
2020-10-05 21:34:52 +00:00
|
|
|
data: {
|
|
|
|
...payload.data,
|
2022-02-17 20:17:59 +00:00
|
|
|
enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off',
|
2020-10-05 21:34:52 +00:00
|
|
|
},
|
2020-10-01 19:37:33 +00:00
|
|
|
};
|
|
|
|
return this._super(store, primaryModelClass, normalizedPayload, id, requestType);
|
|
|
|
},
|
2020-10-08 15:23:59 +00:00
|
|
|
|
|
|
|
serialize() {
|
|
|
|
let json = this._super(...arguments);
|
|
|
|
if (json.enabled === 'On' || json.enabled === 'Off') {
|
|
|
|
const oldEnabled = json.enabled;
|
2020-10-21 16:35:36 +00:00
|
|
|
json.enabled = oldEnabled === 'On' ? 'enable' : 'disable';
|
2020-10-08 15:23:59 +00:00
|
|
|
}
|
|
|
|
json.retention_months = parseInt(json.retention_months, 10);
|
2022-02-14 18:30:48 +00:00
|
|
|
if (isNaN(json.retention_months)) {
|
2020-10-08 15:23:59 +00:00
|
|
|
throw new Error('Invalid number value');
|
|
|
|
}
|
|
|
|
delete json.queries_available;
|
|
|
|
return json;
|
|
|
|
},
|
2020-10-01 19:37:33 +00:00
|
|
|
});
|