UNPKG

forest-express

Version:

Official package for all Forest Express Lianas

37 lines (36 loc) 1.18 kB
"use strict"; var _ = require('lodash'); var JSONAPISerializer = require('jsonapi-serializer').Serializer; var Schemas = require('../../../generators/schemas'); function serializeCards(cards, collectionName, meta) { function getCustomerAttributes() { if (!cards.length) { return []; } var schema = Schemas.schemas[collectionName]; if (!schema) { return []; } return _.map(schema.fields, 'field'); } var customerAttributes = getCustomerAttributes(); var type = "".concat(collectionName, "_stripe_cards"); return new JSONAPISerializer(type, cards, { attributes: ['last4', 'brand', 'funding', 'exp_month', 'exp_year', 'country', 'name', 'address_line1', 'address_line2', 'address_city', 'address_state', 'address_zip', 'address_country', 'cvc_check', 'customer'], customer: { ref: 'id', attributes: customerAttributes }, keyForAttribute: function keyForAttribute(key) { return key; }, typeForAttribute: function typeForAttribute(attr) { if (attr === 'customer') { return collectionName; } return attr; }, meta: meta }); } module.exports = serializeCards;