Skip to content

Commit

Permalink
[Feature #162171019] Updating branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Oluwaseun Jolaoso authored and Oluwaseun Jolaoso committed Dec 6, 2018
2 parents f83bd32 + 6e93f70 commit 9890f2b
Show file tree
Hide file tree
Showing 7 changed files with 817 additions and 1,591 deletions.
48 changes: 48 additions & 0 deletions controllers/UsersController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Response from '../helpers/StatusResponse';
import models from '../models';


const { users, profiles, roles } = models;

/**
* @description UsersController class
*/
class UsersController {
/**
* @description Fetch all the users
* @param {Object} req - HTTP Request
* @param {Object} res - HTTP Response
* @return {Object} Returned object
*/
static async list(req, res) {
try {
const authors = await users.findAll({
include: [profiles, {
model: roles,
as: 'roles',
where: {
role: 'author'
}
}],
attributes: { exclude: ['password'] }
});
if (authors.length === 0) {
Response.notfound(res, {
message: 'No author found',
status: 404
});
} else {
Response.success(res, {
message: 'List of authors',
users: authors
});
}
} catch (error) {
Response.internalServerError(res, {
message: `Something went wrong..${error}`
});
}
}
}

export default UsersController;
1 change: 0 additions & 1 deletion controllers/index.js
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ app.use(passport.initialize());
app.use(passport.session());
app.use(validator());

app.get('/', (req, res) => res.status(200).send({
message: 'Welcome to the Author\'s haven',
}));

app.use('/api/v1/auth', auth);
app.use('/api/v1/auth_twitter', twitterRouter);
app.use('/api/v1/profiles', profiles);
app.use('/api/v1/forgotpassword', user);
app.use('/api/v1/users', user);
passportAuth();

app.use((req, res) => res.status(404).json('not found'));
app.use((req, res) => res.status(404).json({ message: 'not found' }));


app.listen(PORT, () => {
logger.log(`connected on port ${PORT}`);
Expand Down
11 changes: 1 addition & 10 deletions middlewares/UserValidation.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/* eslint-disable lines-between-class-members */
// import { check, validationResult, body } from 'express-validator/check';
// this function validates the User signup function parameters
// invalid user parameters includes:
// existing user email
// invalid email
// password of length less than 8
// password not being alphanumeric
// ctrl + alt + d
// class UserValidation {
/**
* Signup validation class
* classname should match file name and start with capital
Expand All @@ -25,6 +15,7 @@ class UserValidation {
UserValidation.checkUserName(req);
UserValidation.showError(req, res, next);
}

/**
* @param {object} req Takes signup request
* @param {object} res Response to request
Expand Down
Loading

0 comments on commit 9890f2b

Please sign in to comment.