From 35c359e433b3d2053b9b37b04675e7d8592da869 Mon Sep 17 00:00:00 2001 From: Shinsina Date: Fri, 13 Sep 2024 08:58:35 -0500 Subject: [PATCH] Use getAsObject for incoming attributes from input --- .../src/graphql/resolvers/email/newsletter.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/graphql-server/src/graphql/resolvers/email/newsletter.js b/services/graphql-server/src/graphql/resolvers/email/newsletter.js index 7cdc87fc0..818b4bd7a 100644 --- a/services/graphql-server/src/graphql/resolvers/email/newsletter.js +++ b/services/graphql-server/src/graphql/resolvers/email/newsletter.js @@ -16,17 +16,13 @@ module.exports = { updateEmailNewsletterProvider: async (_, { input }, { base4rest, basedb }) => { validateRest(base4rest); const type = 'email/product/newsletter'; - const { - id, - type: providerType, - providerId, - attributes, - } = input; + const { id, type: providerType, providerId } = input; const product = await basedb.strictFindById('platform.Product', id, { projection: { provider: 1 } }); + const attributesFromInput = getAsObject(input, 'attributes'); const existingAttributes = getAsObject(product, 'provider.attributes'); - const mergedAttributes = { ...existingAttributes, ...attributes }; - Object.entries(attributes).forEach(([key, value]) => { + const mergedAttributes = { ...existingAttributes, ...attributesFromInput }; + Object.entries(attributesFromInput).forEach(([key, value]) => { if (value === null) delete mergedAttributes[key]; });