Not creating email record when there is nobody to send it to

This commit is contained in:
Nazar Gargol 2019-11-07 16:00:18 +07:00
parent 7e0da18f85
commit b364fc5e35

View File

@ -52,6 +52,11 @@ const addEmail = async (post) => {
const {members} = await membersService.api.members.list(Object.assign({filter: 'subscribed:true'}, {limit: 'all'}));
const {emailTmpl, emails} = getEmailData(post, members);
// NOTE: don't create email object when there's nobody to send the email to
if (!emails.length) {
return null;
}
const existing = await models.Email.findOne({post_id: post.id}, internalContext);
if (!existing) {