Ghost/ghost/members-csv/unparse
Nazar Gargol c5c20d5efb Extracted members csv serialization logic into separate module
no issue

- This is prep work for extraction into members repository.
2020-06-19 19:33:43 +12:00

34 lines
946 B
Plaintext

const _ = require('lodash');
const papaparse = require('papaparse');
const unparse = (members) => {
const mappedMembers = members.map((member) => {
let stripeCustomerId;
if (member.stripe) {
stripeCustomerId = _.get(member, 'stripe.subscriptions[0].customer.id');
}
let labels = [];
if (member.labels) {
labels = `${member.labels.map(l => l.name).join(',')}`;
}
return {
id: member.id,
email: member.email,
name: member.name,
note: member.note,
subscribed_to_emails: member.subscribed,
complimentary_plan: member.comped,
stripe_customer_id: stripeCustomerId,
created_at: member.created_at,
deleted_at: member.deleted_at,
labels: labels
};
});
return papaparse.unparse(mappedMembers);
};
module.exports.unparse = unparse;