Skip to content

Commit

Permalink
Merge pull request #14 from StackAdapt/jc/ondelete
Browse files Browse the repository at this point in the history
Fix(ITE-146) Refactored structure for OnDelete
  • Loading branch information
illumin04 authored Nov 20, 2024
2 parents 0409391 + 9a11a42 commit acaccc8
Showing 1 changed file with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const destination: DestinationDefinition<Settings> = {
onDelete: async (request, { payload }) => {
const userId = payload.userId
const formattedExternalIds = `["${userId}"]`

const syncId = sha256hash(String(userId))

const mutation = `mutation {
Expand All @@ -78,31 +77,25 @@ const destination: DestinationDefinition<Settings> = {
}
}`

try {
const response = await request(GQL_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: mutation })
})

const result = await response.json()
const response = await request(GQL_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: mutation })
})

if (result.data.deleteProfilesWithExternalIds.userErrors.length > 0) {
const errorMessages = result.data.deleteProfilesWithExternalIds.userErrors.map((e: any) => e.message).join(', ')
throw new IntegrationError(`Profile deletion was not successful: ${errorMessages}`, 'DELETE_FAILED', 400)
const result: {
data: {
deleteProfilesWithExternalIds: {
userErrors: { message: string }[]
}
}
} = await response.json()

return result
} catch (error) {
if (error instanceof IntegrationError) {
throw error
}
throw new IntegrationError(
`Unexpected error occurred in onDelete: ${error instanceof Error ? error.message : String(error)}`,
'UNKNOWN_ERROR',
400
)
if (result.data.deleteProfilesWithExternalIds.userErrors.length > 0) {
const errorMessages = result.data.deleteProfilesWithExternalIds.userErrors.map((e) => e.message).join(', ')
throw new IntegrationError(`Profile deletion was not successful: ${errorMessages}`, 'DELETE_FAILED', 400)
}
return result
},

actions: {
Expand Down

0 comments on commit acaccc8

Please sign in to comment.