@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
27 lines (26 loc) • 841 B
JavaScript
/**
* @hidden
*/
export function transformInteractionDateResponseRaw(entityWithInteractions) {
const { interaction_dates, interactions, ...rest } = entityWithInteractions;
const dates = {};
if (interaction_dates) {
dates.interaction_dates = Object.fromEntries(Object.entries(interaction_dates).map(([key, value]) => [
key,
value ? new Date(value) : null,
]));
}
if (interactions) {
dates.interactions = Object.fromEntries(Object.entries(interactions).map(([key, value]) => [
key,
value
? {
...value,
date: new Date(value.date),
}
: null,
]));
}
// TODO(@joscha): fix the types so we don't need to cast here
return { ...rest, ...dates };
}