Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #960 from Shinsina/get-as-object-usage
Browse files Browse the repository at this point in the history
Use getAsObject for incoming attributes from input
  • Loading branch information
B77Mills authored Sep 13, 2024
2 parents 6d5b83f + 35c359e commit ee8cb4f
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});

Expand Down

0 comments on commit ee8cb4f

Please sign in to comment.