mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 04:03:12 +03:00
16f35df448
refs https://github.com/TryGhost/Team/issues/1469 - allows Portal access to multiple newsletters on a site - allows Portal to update member's newsletter subscription preference
28 lines
905 B
JavaScript
28 lines
905 B
JavaScript
const labsService = require('../../../shared/labs');
|
|
|
|
function formatNewsletterResponse(newsletters) {
|
|
return newsletters.map(({id, name, description, sort_order: sortOrder}) => {
|
|
return {id, name, description, sort_order: sortOrder};
|
|
});
|
|
}
|
|
|
|
module.exports.formattedMemberResponse = function formattedMemberResponse(member) {
|
|
if (!member) {
|
|
return null;
|
|
}
|
|
const data = {
|
|
uuid: member.uuid,
|
|
email: member.email,
|
|
name: member.name,
|
|
firstname: member.name && member.name.split(' ')[0],
|
|
avatar_image: member.avatar_image,
|
|
subscribed: !!member.subscribed,
|
|
subscriptions: member.subscriptions || [],
|
|
paid: member.status !== 'free'
|
|
};
|
|
if (member.newsletters && labsService.isSet('multipleNewsletters')) {
|
|
data.newsletters = formatNewsletterResponse(member.newsletters);
|
|
}
|
|
return data;
|
|
};
|