Extracted members csv serialization logic into separate module

no issue

- This is prep work for extraction into members repository.
This commit is contained in:
Nazar Gargol 2020-06-19 17:23:05 +12:00
parent ca2ab5bbce
commit c5c20d5efb

33
ghost/members-csv/unparse Normal file
View File

@ -0,0 +1,33 @@
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;