Skip to content

Commit

Permalink
chore(import-order-status): check tracking code before track
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgnreis authored Aug 7, 2024
1 parent 7478962 commit a02984d
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions functions/lib/kangu/import-order-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,44 @@ module.exports = async (
trackingId = customTracking.value
}
logger.info(`Tracking #${storeId} ${number} with ID ${trackingId}`)
const { data } = await axios.get(`https://portal.kangu.com.br/tms/transporte/rastrear/${trackingId}`, {
headers: {
'content-type': 'application/json',
token,
accept: 'application/json'
},
timeout: 7000
})
const trackingResult = data?.situacao
if (!trackingResult) return
const status = parseKanguStatus(trackingResult)
if (!status) {
logger.warn(`No parsed fulfillment status for #${storeId} ${number}`, {
trackingId,
trackingResult
})
return
}

if (status !== order.fulfillment_status.current) {
await appSdk.apiRequest(
storeId,
`/orders/${order._id}/fulfillments.json`,
'POST',
{
shipping_line_id: shippingLine._id,
date_time: new Date().toISOString(),
status,
notification_code: `kangu:${trackingResult.dataHora}:${trackingResult.ocorrencia}`,
flags: ['kangu']
if (trackingId) {
const { data } = await axios.get(`https://portal.kangu.com.br/tms/transporte/rastrear/${trackingId}`, {
headers: {
'content-type': 'application/json',
token,
accept: 'application/json'
},
auth
)
logger.info(`#${storeId} ${number} updated to ${status}`)
timeout: 7000
})
const trackingResult = data?.situacao
if (!trackingResult) return
const status = parseKanguStatus(trackingResult)
if (!status) {
logger.warn(`No parsed fulfillment status for #${storeId} ${number}`, {
trackingId,
trackingResult
})
return
}

if (status !== order.fulfillment_status.current) {
await appSdk.apiRequest(
storeId,
`/orders/${order._id}/fulfillments.json`,
'POST',
{
shipping_line_id: shippingLine._id,
date_time: new Date().toISOString(),
status,
notification_code: `kangu:${trackingResult.dataHora}:${trackingResult.ocorrencia}`,
flags: ['kangu']
},
auth
)
logger.info(`#${storeId} ${number} updated to ${status}`)
}
} else {
logger.info(`#${storeId} ${number} doenst have tracking code`)
}

}

0 comments on commit a02984d

Please sign in to comment.