refactor: 💡 application serializeAttribute (#1772)
* refactor: 💡 application serializeAttribute
This commit is contained in:
1 parent
66fc50bf9e
commit
7ee52ea06f
4 files changed
+67
-32
No files matched your search
@@ -42,6 +42,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
*/
|
||||
serializeAttribute(snapshot, json, key, attribute) {
|
||||
const { type, options } = attribute;
|
||||
const { type: recordType } = snapshot.record;
|
||||
let value = super.serializeAttribute(...arguments);
|
||||
// Remove secret attributes that are null or empty
|
||||
if (options.isSecret) {
|
||||
@@ -72,6 +73,21 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
}
|
||||
delete json[key];
|
||||
}
|
||||
// If an attribute has a `for` option, it must match the
|
||||
// record's `type`, else the attribute is excluded
|
||||
// from serialization.
|
||||
//note: This doesn't handle secrets yet, we can add support for them if needed.
|
||||
if (
|
||||
options?.for &&
|
||||
options.for !== recordType &&
|
||||
!options.for.includes(recordType)
|
||||
) {
|
||||
if (options.isNestedAttribute) {
|
||||
delete json?.attributes?.[key];
|
||||
} else {
|
||||
delete json[key];
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,21 +24,6 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
serializeAttribute(snapshot, json, key, attribute) {
|
||||
const { type } = snapshot.record;
|
||||
super.serializeAttribute(...arguments);
|
||||
const { options } = attribute;
|
||||
|
||||
// If an attribute has a `for` option, it must match the
|
||||
// record's `type`, else the attribute is excluded
|
||||
// from serialization.
|
||||
if (options?.for && !options.for.includes(type)) {
|
||||
if (options.isNestedAttribute) {
|
||||
delete json?.attributes?.[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Password serialization omits `attributes`.
|
||||
* @return {object}
|
||||
|
||||
@@ -32,23 +32,6 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
serializeAttribute(snapshot, json, key, attribute) {
|
||||
super.serializeAttribute(...arguments);
|
||||
const { options } = attribute;
|
||||
const { type } = snapshot.record;
|
||||
|
||||
// If an attribute has a `for` option, it must match the
|
||||
// record's `type`, else the attribute is excluded
|
||||
// from serialization.
|
||||
if (options?.for && options.for !== type) {
|
||||
if (options.isNestedAttribute) {
|
||||
delete json.attributes[key];
|
||||
} else {
|
||||
delete json[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serializeVaultGeneric() {
|
||||
const serialized = super.serialize(...arguments);
|
||||
if (serialized.attributes) {
|
||||
|
||||
Reference in new issue
Block a user