- Route to approve submissions
This commit is contained in:
@@ -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',
|
||||
@@ -316,6 +316,31 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
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;
|
||||
var errors = [];
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user