From 556085ebd0479918ae3da3556580f92a44df20cf Mon Sep 17 00:00:00 2001 From: Mike Fitzpatrick Date: Sun, 4 Mar 2018 22:16:16 -0500 Subject: [PATCH] no message --- models/profile.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/models/profile.js b/models/profile.js index 358fa54..0470b9a 100644 --- a/models/profile.js +++ b/models/profile.js @@ -169,15 +169,24 @@ module.exports = { allMessageImages: (e, profileId) => { const promise = new Promise((resolve, reject) => { ProfileModel - .find({ _id: profileId, 'messages.$.image': { $exists: true } }) - .select('messages') - .exec((err, result) => { + .findById(profileId, (err, profile) => { if (err) { reject(err); } - if (result) { - resolve(result); + if (profile) { + profile.messages + .find({ 'image': { $exists: true } }) + .select('image -_id') + .exec((err, result) => { + if (err) { + reject(err); + } + + if (result) { + resolve(result); + } + }); } }); });