mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Extracted members csv serialization logic into separate module
no issue - This is prep work for extraction into members repository.
This commit is contained in:
parent
ca2ab5bbce
commit
c5c20d5efb
33
ghost/members-csv/unparse
Normal file
33
ghost/members-csv/unparse
Normal 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;
|
Loading…
Reference in New Issue
Block a user