Skip to content

Commit

Permalink
fix: fix updating from account section
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Oct 2, 2023
1 parent e138767 commit 4fd8bf7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,28 @@ export const getCustomerConsents: GetCustomerConsents = async (payload) => {
export const updateCustomerConsents: UpdateCustomerConsents = async (payload) => {
try {
const { customer, consents } = payload;

const existingAccountData = formatUpdateAccount(customer);

const newMetadata = Object.fromEntries(
consents
.filter(({ value }) => value !== '')
.map(({ name, value }) => {
const isBoolean = value === true || value === false;

if (isBoolean) {
return [name, value === true ? 'on' : 'off'];
}

return [name, value];
}),
);

const params = {
...formatUpdateAccount(customer),
...existingAccountData,
metadata: {
...existingAccountData.metadata,
...newMetadata,
consents: JSON.stringify(consents),
},
};
Expand Down

0 comments on commit 4fd8bf7

Please sign in to comment.