This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add the request return trip controller and route - added test for the feature - add the protect routes middleware - changed the reset route to follow conventions - modified the reset feature swagger documentation [Maintains #170947553]
- Loading branch information
Showing
16 changed files
with
443 additions
and
100 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
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,55 @@ | ||
import db from '../models'; | ||
import Response from '../utils/ResponseHandler'; | ||
import { verifyToken } from '../utils/tokenHandler'; | ||
|
||
/** | ||
* @description protect route class | ||
* @class protectRoutes | ||
*/ | ||
export default class protectRoutes { | ||
/** @description validate if user is signup | ||
* @static | ||
* @param {object} req | ||
* @param {object} res | ||
* @param {object} next | ||
* @returns {object} next | ||
* @memberof protectRoutes | ||
*/ | ||
static async verifyUser(req, res, next) { | ||
try { | ||
const { token } = req.headers; | ||
if (!token) { | ||
return Response.errorResponse(res, 401, res.__('No token provided')); | ||
} | ||
const payload = verifyToken(token); | ||
const user = await db.User.findOne({ | ||
where: { | ||
id: payload.id | ||
} | ||
}); | ||
if (!user) { | ||
return Response.errorResponse(res, 401, res.__('you are not authorised for this operation')); | ||
} | ||
req.payload = payload; | ||
req.user = user; | ||
return next(); | ||
} catch (err) { | ||
if (err.name === 'JsonWebTokenError') { | ||
return Response.errorResponse(res, 400, res.__('token must be provided and valid')); | ||
} | ||
return Response.errorResponse(res, 500, res.__('server error')); | ||
} | ||
} | ||
|
||
/** | ||
* @param {object} req | ||
* @param {object} res | ||
* @param {object} next | ||
* @returns {object} user | ||
*/ | ||
static async verifyRequester(req, res, next) { | ||
const { user } = req; | ||
if (user.role !== 'requester') Response.errorResponse(res, 401, res.__('you are not authorised for this operation')); | ||
next(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Facilities', { | ||
id: { | ||
allowNull: false, | ||
type: Sequelize.STRING, | ||
primaryKey: true | ||
}, | ||
facilityName: { | ||
type: Sequelize.STRING, | ||
}, | ||
location: { | ||
type: Sequelize.STRING | ||
}, | ||
image: { | ||
type: Sequelize.STRING | ||
}, | ||
numOfRooms: { | ||
type: Sequelize.INTEGER, | ||
defaultValue: 0 | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Facilities'); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import express from 'express'; | ||
import tripsController from '../controllers/tripsController'; | ||
import { requestRules } from '../validation/validationRules'; | ||
import { requestRules, returnTripRules } from '../validation/validationRules'; | ||
import validationResult from '../validation/validationResult'; | ||
import { verifyRequester } from '../middlewares/verifyUser'; | ||
import { decode } from '../utils/tokenHandler'; | ||
import protectRoute from '../middlewares/protectRoute'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/one-way', decode, verifyRequester, requestRules, validationResult, tripsController.createRequest); | ||
|
||
router.post('/one-way', protectRoute.verifyUser, protectRoute.verifyRequester, requestRules, validationResult, tripsController.createRequest); | ||
router.post('/return', protectRoute.verifyUser, protectRoute.verifyRequester, returnTripRules, validationResult, tripsController.createReturnRequest); | ||
export default router; |
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
Oops, something went wrong.