Skip to content

Commit

Permalink
Re-formatted mailing lists
Browse files Browse the repository at this point in the history
  • Loading branch information
danrowden committed Aug 26, 2024
1 parent a9b8c4f commit 8ca66d0
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,26 @@ const action: ActionDefinition<Settings, Payload> = {
type: 'string',
required: true
},
value: {
label: 'value',
subscribed: {
label: 'subscribed',
description:
'true indicates that the user is to be added to the list, false will remove the user from the list.',
type: 'boolean',
required: true
}
},
default: {
'@arrayPath': [
'$.properties.mailing_lists',
{
list_id: {
'@path': '$.list_id'
},
subscribed: {
'@path': '$.subscribed'
}
}
]
}
},
source: {
Expand Down Expand Up @@ -114,12 +127,11 @@ const action: ActionDefinition<Settings, Payload> = {

/* Re-shape mailing list data from a list of objects to a single object for the API */
const formattedMailingLists: Record<string, boolean> = {}
type listObj = { list_id: string; subscribed: boolean }
if (payload.mailingLists) {
for (const value of Object.values(payload.mailingLists)) {
if (typeof value === 'object' && 'list_id' in value && 'value' in value) {
formattedMailingLists[(value as { list_id: string; value: boolean }).list_id] = (
value as { list_id: string; value: boolean }
).value
for (const list of Object.values(payload.mailingLists)) {
if (typeof list === 'object' && 'list_id' in list && 'subscribed' in list) {
formattedMailingLists[(list as listObj).list_id] = (list as listObj).subscribed
}
}
}
Expand Down

0 comments on commit 8ca66d0

Please sign in to comment.