Skip to content

Commit

Permalink
Merge f7adbbd into 71b32ab
Browse files Browse the repository at this point in the history
  • Loading branch information
d-beloved committed Sep 19, 2018
2 parents 71b32ab + f7adbbd commit fcd77a2
Show file tree
Hide file tree
Showing 6 changed files with 1,579 additions and 1,469 deletions.
45 changes: 44 additions & 1 deletion server/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Op } from 'sequelize';

import bcrypt from 'bcrypt';
import sendgrid from '@sendgrid/mail';
import env from 'dotenv';
Expand All @@ -13,7 +15,6 @@ import { User } from '../models';
sendgrid.setApiKey(process.env.SENDGRID_API_KEY);
env.config();


/**
*
* @description controller class with methods for user endpoints
Expand Down Expand Up @@ -264,6 +265,48 @@ class UsersController {
}).catch(next);
}

/**
* @description Static method for admin to get a list of all users
* @param {object} req body of the Admin's request
* @param {object} res body of the response message
* @param {function} next next function to be called
* @returns {object} The body of the resposne message
*/
static adminGetUsers(req, res, next) {
const { role } = req.query;
if (!role) {
User.findAll({
where: {
role: {
[Op.or]: ['user', 'author']
}
},
attributes: {
exclude: ['hash']
}
})
.then(users => res.status(200).json({
message: 'All registered users returned',
status: 'success',
profiles: users,
})).catch(next);
} else {
User.findAll({
where: {
role
},
attributes: {
exclude: ['hash']
}
})
.then(users => res.status(200).json({
message: 'All registered users/authors returned',
status: 'success',
profiles: users,
})).catch(next);
}
}

/**
* @description Send recovery mail to user's email
* @param {obj} req response body
Expand Down
Loading

0 comments on commit fcd77a2

Please sign in to comment.