-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(manager-view-single-request): A manager can view a single request
- create a middleware to check the role and pass the requesterId to controller - create tests to cover the new implementation [Finishes #169779349]
- Loading branch information
1 parent
b30731d
commit 3f64a16
Showing
10 changed files
with
304 additions
and
197 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import requestsSearch from '../utils/requestsSearch'; | ||
import findUser from '../helpers/findUser'; | ||
import responseUtil from '../utils/responseUtil'; | ||
import strings from '../utils/strings'; | ||
|
||
const managerViewRequest = async (req, res, next) => { | ||
const { role } = req.user.payload; | ||
const { id } = req.params; | ||
let requesterId; | ||
const request = await requestsSearch({ id }); | ||
let user; | ||
|
||
if (!request.length || !request) { | ||
return responseUtil(res, 404, strings.user.requests.NO_REQUESTS); | ||
} | ||
|
||
switch (role) { | ||
case 4: | ||
requesterId = request[0].dataValues.requester.id; | ||
user = await findUser({ id: requesterId }); | ||
if (user.lineManager !== req.user.payload.id) { | ||
return responseUtil(res, 403, strings.user.requests.NOT_MANAGER); | ||
} | ||
break; | ||
case 6: | ||
requesterId = req.user.payload.id; | ||
break; | ||
} | ||
req.requesterId = requesterId; | ||
return next(); | ||
}; | ||
|
||
export default managerViewRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.