Skip to content

Commit

Permalink
fix(intercom): fix date conversion from unix timestamp to js date of …
Browse files Browse the repository at this point in the history
…intercom attributes
  • Loading branch information
jeffladiray committed Jun 14, 2021
1 parent a0eb563 commit 7526614
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/integrations/intercom/serializers/intercom-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ const JSONAPISerializer = require('jsonapi-serializer').Serializer;
function serializeIntercomAttributes(attributes, collectionName, meta) {
const type = `${collectionName}_intercom_attributes`;

const unixTimestampToDateOrNull = (unixTimestamp) =>
unixTimestamp && new Date(unixTimestamp * 1000);

// Attributes keys ending with `_at` are unix timestamp
// thus they need to be converted to js Date
Object.entries(attributes).forEach(([attributeKey, attributeValue]) => {
if (attributeKey.endsWith('_at')) {
attributes[attributeKey] = unixTimestampToDateOrNull(attributeValue);
}
});

return new JSONAPISerializer(type, attributes, {
attributes: [
'email',
Expand Down

0 comments on commit 7526614

Please sign in to comment.