Improve processed data
Move setting unparsed data to cards before breakdown so that a successful breakdown overwrites cards. Label what kind of data unparsed data is. Condense string filters into arrays.
This commit is contained in:
parent
6aa5944f90
commit
1659fa65a9
@ -11,28 +11,24 @@ export async function processTrip(activity, usefulRequestHeaders) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
let body = await res.json()
|
let body = await res.json()
|
||||||
let unparsedData = body
|
let unparsedData = { body }
|
||||||
let cards = body?.data?.cards?.filter((card) => {
|
let cards = body?.data?.cards?.filter((card) => {
|
||||||
return card.type != "MapCard" && card.type != "TripStatsCard"
|
return !["MapCard", "TripStatsCard"].includes(card.type)
|
||||||
})
|
})
|
||||||
|
if (cards?.length) {
|
||||||
|
unparsedData = { cards }
|
||||||
|
}
|
||||||
let breakdown =
|
let breakdown =
|
||||||
cards?.find((card) => card.type == "TripAllPartiesBreakdownCard") ||
|
cards?.find((card) => card.type == "TripAllPartiesBreakdownCard") ||
|
||||||
cards?.find((card) => card.type == "TripBreakdownCard")
|
cards?.find((card) => card.type == "TripBreakdownCard")
|
||||||
if (breakdown) {
|
if (breakdown) {
|
||||||
let components = breakdown.components?.filter((comp) => {
|
let components = breakdown.components?.filter((comp) => {
|
||||||
return (
|
return !["header", "divider", "collapsableSection"].includes(comp.type)
|
||||||
comp.type != "header" &&
|
|
||||||
comp.type != "divider" &&
|
|
||||||
comp.type != "collapsableSection"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
if (components?.length) {
|
if (components?.length) {
|
||||||
unparsedData = components
|
unparsedData = { components }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cards?.length) {
|
|
||||||
unparsedData = cards
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
uuid: activity.uuid,
|
uuid: activity.uuid,
|
||||||
recognizedAt: new Date((activity.recognizedAt ?? 1) * 1000).toISOString(),
|
recognizedAt: new Date((activity.recognizedAt ?? 1) * 1000).toISOString(),
|
||||||
|
Loading…
Reference in New Issue
Block a user