ForestAdmin/forest-express

View on GitHub
src/integrations/close.io/serializers/closeio-leads.js

Summary

Maintainability
A
1 hr
Test Coverage
F
33%
const JSONAPISerializer = require('jsonapi-serializer').Serializer;

function serializeCloseioLeads(attributes, collectionName, meta) {
  const type = `${collectionName}_closeio_leads`;

  return new JSONAPISerializer(type, attributes, {
    attributes: ['url', 'created_by_name', 'display_name', 'status_label',
      'date_created', 'date_updated', 'description', 'emails'],
    emails: {
      ref: 'id',
      included: false,
      ignoreRelationshipData: true,
      nullIfMissing: true,
      relationshipLinks: {
        related(dataSet) {
          return {
            href: `/forest/${collectionName}_closeio_leads/${
              dataSet.id}/emails`,
          };
        },
      },
    },
    keyForAttribute(key) { return key; },
    meta,
  });
}

module.exports = serializeCloseioLeads;