-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(request): manager reject trip request
- add request validation schema to validate the request Id - add request middleware to verify manager - add a controller to reject a trip request [Finishes #167727738]
- Loading branch information
Showing
16 changed files
with
276 additions
and
41 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require('@babel/register'); | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
|
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
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,35 @@ | ||
import response from '../utils/response'; | ||
import messages from '../utils/messages'; | ||
import DbServices from '../services/dbServices'; | ||
import models from '../models'; | ||
|
||
const { User, Request } = models; | ||
const { findOneIncludeModel } = DbServices; | ||
|
||
const verifyRequestLineManager = async (req, res, next) => { | ||
try { | ||
const { id: loggedInUserId } = req.decoded; | ||
const { requestId } = req.params; | ||
const table2 = { | ||
model: User, | ||
alias: 'User', | ||
column: { lineManager: loggedInUserId } | ||
}; | ||
const data = await findOneIncludeModel(Request, requestId, table2); | ||
|
||
const requestLineManagerId = data.User.lineManager; | ||
const manager = loggedInUserId === requestLineManagerId; | ||
if (!manager) { | ||
return response(res, 401, 'error', { | ||
message: messages.unauthorized | ||
}); | ||
} | ||
next(); | ||
} catch (error) { | ||
return response(res, 500, 'error', { | ||
errors: error | ||
}); | ||
} | ||
}; | ||
|
||
export default verifyRequestLineManager; |
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
Oops, something went wrong.