mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
b552727b69
refs https://github.com/TryGhost/Team/issues/1076 - The "products" is a legacy term for what is now "tiers" since multiple tiers feature introduction in https://github.com/TryGhost/Ghost/releases/tag/v4.39.0 - Note, the "tiers" is a field meant for informational purposes and cannot be imported back into Ghost site.
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
const _ = require('lodash');
|
|
const papaparse = require('papaparse');
|
|
const DEFAULT_COLUMNS = [
|
|
'id',
|
|
'email',
|
|
'name',
|
|
'note',
|
|
'subscribed_to_emails',
|
|
'complimentary_plan',
|
|
'stripe_customer_id',
|
|
'created_at',
|
|
'deleted_at',
|
|
'labels',
|
|
'tiers'
|
|
];
|
|
|
|
const unparse = (members, columns = DEFAULT_COLUMNS.slice()) => {
|
|
columns = columns.map((column) => {
|
|
if (column === 'subscribed') {
|
|
return 'subscribed_to_emails';
|
|
}
|
|
return column;
|
|
});
|
|
const mappedMembers = members.map((member) => {
|
|
if (member.error && !columns.includes('error')) {
|
|
columns.push('error');
|
|
}
|
|
|
|
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(',');
|
|
}
|
|
|
|
let tiers = '';
|
|
|
|
if (Array.isArray(member.tiers)) {
|
|
tiers = member.tiers.map((tier) => {
|
|
return tier.name;
|
|
}).join(',');
|
|
}
|
|
|
|
return {
|
|
id: member.id,
|
|
email: member.email,
|
|
name: member.name,
|
|
note: member.note,
|
|
subscribed_to_emails: member.subscribed,
|
|
complimentary_plan: member.comped || member.complimentary_plan,
|
|
stripe_customer_id: _.get(member, 'subscriptions[0].customer.id') || member.stripe_customer_id,
|
|
created_at: member.created_at,
|
|
deleted_at: member.deleted_at,
|
|
labels: labels,
|
|
tiers: tiers,
|
|
error: member.error || null
|
|
};
|
|
});
|
|
|
|
return papaparse.unparse(mappedMembers, {
|
|
columns
|
|
});
|
|
};
|
|
|
|
module.exports = unparse;
|