mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
Updated members-csv to handle error column when unparsing
no-issue This also allows for different the member object structure returned from parse
This commit is contained in:
parent
05d5310343
commit
019d99fcc2
1 changed files with 29 additions and 11 deletions
|
@ -2,15 +2,30 @@ const _ = require('lodash');
|
|||
const papaparse = require('papaparse');
|
||||
|
||||
const unparse = (members) => {
|
||||
const columns = new Set([
|
||||
'id',
|
||||
'email',
|
||||
'name',
|
||||
'note',
|
||||
'subscribed_to_emails',
|
||||
'complimentary_plan',
|
||||
'stripe_customer_id',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
'labels'
|
||||
]);
|
||||
const mappedMembers = members.map((member) => {
|
||||
let stripeCustomerId;
|
||||
|
||||
if (member.stripe) {
|
||||
stripeCustomerId = _.get(member, 'stripe.subscriptions[0].customer.id');
|
||||
if (member.error) {
|
||||
columns.add('error');
|
||||
}
|
||||
let labels = [];
|
||||
if (member.labels) {
|
||||
labels = `${member.labels.map(l => l.name).join(',')}`;
|
||||
|
||||
let labels = '';
|
||||
if (typeof member.labels === 'string') {
|
||||
labels = member.labels;
|
||||
} else if (Array.isArray(member.labels)) {
|
||||
labels = member.labels.map((l) => {
|
||||
return typeof l === 'string' ? l : l.name;
|
||||
}).join(',');
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -19,15 +34,18 @@ const unparse = (members) => {
|
|||
name: member.name,
|
||||
note: member.note,
|
||||
subscribed_to_emails: member.subscribed,
|
||||
complimentary_plan: member.comped,
|
||||
stripe_customer_id: stripeCustomerId,
|
||||
complimentary_plan: member.comped || member.complimentary_plan,
|
||||
stripe_customer_id: _.get(member, 'stripe.subscriptions[0].customer.id') || member.stripe_customer_id,
|
||||
created_at: member.created_at,
|
||||
deleted_at: member.deleted_at,
|
||||
labels: labels
|
||||
labels: labels,
|
||||
error: member.error || null
|
||||
};
|
||||
});
|
||||
|
||||
return papaparse.unparse(mappedMembers);
|
||||
return papaparse.unparse(mappedMembers, {
|
||||
columns: Array.from(columns.values())
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = unparse;
|
||||
|
|
Loading…
Add table
Reference in a new issue