Ghost/core/server/services/members/utils.js
Rishabh 16f35df448 Added newsletters to Portal site data
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
2022-04-05 22:23:39 +05:30

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;
};