diff --git a/models/profile.js b/models/profile.js index 05e0364..57a20c1 100644 --- a/models/profile.js +++ b/models/profile.js @@ -169,7 +169,7 @@ module.exports = { allSubmitted: (e) => { const promise = new Promise((resolve, reject) => { ProfileModel - .find({ submitted: true }) + .find({ submitted: true, approved: true }) .sort({ order: 1 }) .populate({ path: 'messages', @@ -315,6 +315,31 @@ module.exports = { e.emit('allChatImagesSent', err, null); }); }, + + approveSubmission: (e, profileId) => { + const promise = new Promise((resolve, reject) => { + ProfileModel.findOneAndUpdate( + { _id: profileId }, + { $set: { approved: true } }, + { new: true }, + (err, result) => { + if (err) { + reject(err); + } + + if (result) { + resolve(result); + } + }); + }); + + promise.then((result) => { + e.emit('approveSubmission', null, result); + }) + .catch((err) => { + e.emit('approveSubmission', err, null); + }); + }, create: (e, profiles) => { var count = profiles.length; diff --git a/routes/profiles.js b/routes/profiles.js index cc00a18..1a552b8 100644 --- a/routes/profiles.js +++ b/routes/profiles.js @@ -102,6 +102,24 @@ function updateMessage (req, res, next) { }); } +Router.route('/approve/:id') + .get((req, res) => { + var ProfileEvents = new EventEmitter(); + var id = req.params.id; + + ProfileEvents.once('approveSubmission', (err, result) => { + if (err) { + res.status(500).json({ message: 'Could not approve user profile submission', err: err, profile: profile }); + } + + if (result) { + res.status(200).json(result); + } + }); + + Profiles.approveSubmission(ProfileEvents, id); + }); + Router.route('/find' + ParamStr) .get((req, res) => { Token.verifyThen(req.get('authorization'), 'view', (err, decoded) => {