Skip to content

Commit

Permalink
feature(List users functionality): Users should be able to view other…
Browse files Browse the repository at this point in the history
… users profile

Apply TTL feedback
[Fixes #162727477]
  • Loading branch information
daniellamarr committed Jan 22, 2019
1 parent 96f3e9d commit ce7a7aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/controllers/UsersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,6 @@ class UsersController {
try {
const { artistId } = req.params;

/* eslint-disable no-restricted-globals */
if (isNaN(artistId)) {
const response = new Response(
'Bad Request',
400,
'Artist ID must be an integer',
);
return res.status(response.code).json(response);
}

const artist = await User.findOne({
where: {
id: artistId,
Expand Down
23 changes: 23 additions & 0 deletions src/middlewares/UserMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ class UserMiddleware {
return res.status(response.code).json(response);
}
}

/**
* Validate Password
* @param {object} req
* @param {object} res
* @param {function} next
* @memberof UserMiddleware
* @returns {object} error object if artist id is not a number
*/
static async validateArtistID(req, res, next) {
const { artistId } = req.params;
/* eslint-disable no-restricted-globals */
if (isNaN(artistId)) {
const response = new Response(
'Bad Request',
400,
'Artist ID must be an integer',
);
return res.status(response.code).json(response);
}

next();
}
}

export default UserMiddleware;
2 changes: 2 additions & 0 deletions src/routes/userRouter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express';
import UsersController from '../controllers/UsersController';
import TokenAuthenticate from '../helpers/TokenAuthenticate';
import UserMiddleware from '../middlewares/UserMiddleware';

const userRouter = express.Router();

Expand All @@ -13,6 +14,7 @@ userRouter.get(
userRouter.get(
'/artists/:artistId',
TokenAuthenticate.tokenVerify,
UserMiddleware.validateArtistID,
UsersController.getOneArtist,
);

Expand Down

0 comments on commit ce7a7aa

Please sign in to comment.