UNPKG

forest-express

Version:

Official package for all Forest Express Lianas

37 lines (36 loc) 1.24 kB
"use strict"; var _ = require('lodash'); var JSONAPISerializer = require('jsonapi-serializer').Serializer; var Schemas = require('../../../generators/schemas'); function serializeBankAccounts(bankAccounts, collectionName, meta) { function getCustomerAttributes() { if (!bankAccounts.length) { return []; } var schema = Schemas.schemas[collectionName]; if (!schema) { return []; } return _.map(schema.fields, 'field'); } var customerAttributes = getCustomerAttributes(); var type = "".concat(collectionName, "_stripe_bank_accounts"); return new JSONAPISerializer(type, bankAccounts, { attributes: ['account', 'account_holder_name', 'account_holder_type', 'bank_name', 'country', 'currency', 'default_for_currency', 'fingerprint', 'last4', 'rooting_number', 'status', 'customer'], customer: { ref: Schemas.schemas[collectionName].idField, attributes: customerAttributes }, keyForAttribute: function keyForAttribute(key) { return key; }, typeForAttribute: function typeForAttribute(attr) { if (attr === 'customer') { return collectionName; } return attr; }, meta: meta }); } module.exports = serializeBankAccounts;