From d53cfbcc3318e15ee36ee46515c6cb72446bfd8c Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 14 Feb 2022 11:14:52 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20simplify=20nested=20?= =?UTF-8?q?fields=20normalization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/serializers/application.js | 23 ++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index dcc33eff6..0b20dd128 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -234,11 +234,13 @@ export default class ApplicationSerializer extends RESTSerializer { */ normalizeNestedAttributes(typeClass, hash) { typeClass.attributes.forEach((attribute) => { - const { isNestedAttribute } = attribute.options; - const attributeValue = hash.attributes?.[attribute.name]; - if (isNestedAttribute && typeof attributeValue != 'undefined') { - hash[attribute.name] = attributeValue; - } + const { + name, + options: { isNestedAttribute }, + } = attribute; + const value = hash.attributes?.[name]; + const isUndefined = value === undefined; + if (isNestedAttribute && !isUndefined) hash[name] = value; }); return hash; } @@ -261,15 +263,8 @@ export default class ApplicationSerializer extends RESTSerializer { name, options: { isNestedSecret }, } = attribute; - const attributeValue = hash.secrets?.[name]; - - // FIXME: This could be improved - if (isNestedSecret) { - hash[name] = null; - if (typeof attributeValue != 'undefined') { - hash[name] = attributeValue; - } - } + const value = hash.secrets?.[name]; + if (isNestedSecret) hash[name] = value; }); return hash; }