-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fevi
committed
Aug 22, 2020
1 parent
54981f5
commit cba0698
Showing
11 changed files
with
269 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,17 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { validationResult } from 'express-validator'; | ||
import { RequestValidationError } from '../errors/request-validation-error'; | ||
|
||
export const validateRequest = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
const errors = validationResult(req); | ||
|
||
if (!errors.isEmpty()) { | ||
throw new RequestValidationError(errors.array()); | ||
} | ||
|
||
next(); | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import express from 'express'; | ||
import express, { Request, Response } from 'express'; | ||
import { body } from 'express-validator'; | ||
|
||
import { validateRequest } from '../middlewares/validate-request'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/api/users/signin', (req, res) => { | ||
res.send('Hi there!'); | ||
}); | ||
router.post( | ||
'/api/users/signin', | ||
[ | ||
body('email') | ||
.isEmail() | ||
.withMessage('Email must be valid'), | ||
body('password') | ||
.trim() | ||
.notEmpty() | ||
.withMessage('You must supply a password') | ||
], | ||
validateRequest, | ||
(req: Request, res: Response) => {} | ||
); | ||
|
||
export { router as signinRouter }; |
Oops, something went wrong.