Skip to content

Commit

Permalink
fix: prevent saving "undefined" tracking code on tag creation
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Sep 17, 2024
1 parent 493c215 commit ccb6fd5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions functions/routes/ecom/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ exports.post = ({ appSdk }, req, res) => {
logger.info(`Start creating tag for #${storeId} ${orderId}`)
const data = await createTag(order, storeId, appData, appSdk)
logger.info(`Tag created for #${storeId} ${orderId}`, { data })
trackingCodes.push({
code: String(data['@id'] || data.id),
link: 'https://www.freteclick.com.br/rastreamento',
tag: 'freteclick'
})
await appSdk.apiRequest(
storeId,
`/orders/${orderId}/shipping_lines/${shippingLine._id}.json`,
'PATCH',
{ tracking_codes: trackingCodes },
auth
)
const trackingId = data['@id'] || data.id
if (trackingId) {
trackingCodes.push({
code: String(trackingId),
link: 'https://www.freteclick.com.br/rastreamento',
tag: 'freteclick'
})
await appSdk.apiRequest(
storeId,
`/orders/${orderId}/shipping_lines/${shippingLine._id}.json`,
'PATCH',
{ tracking_codes: trackingCodes },
auth
)
}
}
}
}
Expand Down

0 comments on commit ccb6fd5

Please sign in to comment.