chore: convert writeOnce to writeOnly

This commit is contained in:
Randall Morey committed 2022-01-21 12:43:45 -05:00
1 parent cd60c0bbc3
commit d8aaddfcca
2 files changed
+8 -6

No files matched your search

@@ -73,14 +73,14 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
writeOnce: true,
writeOnly: true,
description: '',
})
access_key_id;
@attr('string', {
isNestedAttribute: true,
writeOnce: true,
writeOnly: true,
description: '',
})
secret_access_key;
@@ -107,14 +107,14 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
writeOnce: true,
writeOnly: true,
description: '',
})
secret_id;
@attr('string', {
isNestedAttribute: true,
writeOnce: true,
writeOnly: true,
description: '',
})
secret_value;
+4 -2
View File
@@ -43,8 +43,6 @@ export default class ApplicationSerializer extends RESTSerializer {
if (type === 'string' && json[key] === '') json[key] = null;
// Do not serialize read-only attributes.
if (options.readOnly) delete json[key];
// Only serialize write-once fields on create.
if (options.writeOnce && !snapshot.record.isNew) delete json[key];
// Version is sent only if it has a non-nullish value
if (key === 'version') {
if (json[key] === null || json[key] === undefined) delete json[key];
@@ -207,6 +205,10 @@ export default class ApplicationSerializer extends RESTSerializer {
const scopeID = get(normalizedHash, 'scope.id');
if (scopeID) normalizedHash.scope.scope_id = scopeID;
normalizedHash = this.normalizeNestedAttributes(typeClass, normalizedHash);
// Delete any lingering values on write-only fields
typeClass.attributes.forEach((attribute) => {
if (attribute.options.writeOnly) hash[attribute.name] = null;
});
return super.normalize(typeClass, normalizedHash);
}