Files
threshold-ui/addons/api/addon/serializers/credential.js
T
Cameron Perera b02dc0aa43 fix: 🐛 Remove json_object from payload for non-json credentials (#1576)
* fix: 🐛 Remove json_object from payload for non-json credentials

* refactor: 💡 update new route logic for type specific attributes

* test: 💍 remove typeIn and use fillIn for json credential test
2023-01-12 16:28:43 -06:00

46 lines
1.2 KiB
JavaScript

import ApplicationSerializer from './application';
import { copy } from 'ember-copy';
export default class CredentialSerializer extends ApplicationSerializer {
/**
* @override
* @method serialize
* @param {Snapshot} snapshot
*/
/**
* @type {boolean}
*/
serializeScopeID = false;
serialize() {
const serialized = super.serialize(...arguments);
if (serialized.type === 'json') {
delete serialized.attributes.username;
if (serialized?.attributes?.json_object) {
serialized.attributes.object = JSON.parse(
serialized.attributes.json_object
);
delete serialized.attributes.json_object;
}
} else {
delete serialized.attributes.json_object;
}
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = copy(hash, true);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields as we don't track them after being created/updated
normalized.data.attributes.password = '';
normalized.data.attributes.private_key = '';
normalized.data.attributes.private_key_passphrase = '';
normalized.data.attributes.json_object = '';
return normalized;
}
}