Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
✨ Update source code to work with express-validator 6.*. Fixes #231
Browse files Browse the repository at this point in the history
  • Loading branch information
wildlyinaccurate authored and peterblazejewicz committed Nov 1, 2019
1 parent e00a8a5 commit f052852
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/controllers/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const getContact = (req: Request, res: Response) => {
* POST /contact
* Send a contact form via Nodemailer.
*/
export const postContact = (req: Request, res: Response) => {
check("name", "Name cannot be blank").not().isEmpty();
check("email", "Email is not valid").isEmail();
check("message", "Message cannot be blank").not().isEmpty();
export const postContact = async (req: Request, res: Response) => {
await check("name", "Name cannot be blank").not().isEmpty().run(req);
await check("email", "Email is not valid").isEmail().run(req);
await check("message", "Message cannot be blank").not().isEmpty().run(req);

const errors = validationResult(req);

Expand Down
42 changes: 21 additions & 21 deletions src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export const getLogin = (req: Request, res: Response) => {
* POST /login
* Sign in using email and password.
*/
export const postLogin = (req: Request, res: Response, next: NextFunction) => {
check("email", "Email is not valid").isEmail();
check("password", "Password cannot be blank").isLength({min: 1});
export const postLogin = async (req: Request, res: Response, next: NextFunction) => {
await check("email", "Email is not valid").isEmail().run(req);
await check("password", "Password cannot be blank").isLength({min: 1}).run(req);
// eslint-disable-next-line @typescript-eslint/camelcase
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
await sanitize("email").normalizeEmail({ gmail_remove_dots: false }).run(req);

const errors = validationResult(req);

Expand Down Expand Up @@ -79,12 +79,12 @@ export const getSignup = (req: Request, res: Response) => {
* POST /signup
* Create a new local account.
*/
export const postSignup = (req: Request, res: Response, next: NextFunction) => {
check("email", "Email is not valid").isEmail();
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
check("confirmPassword", "Passwords do not match").equals(req.body.password);
export const postSignup = async (req: Request, res: Response, next: NextFunction) => {
await check("email", "Email is not valid").isEmail().run(req);
await check("password", "Password must be at least 4 characters long").isLength({ min: 4 }).run(req);
await check("confirmPassword", "Passwords do not match").equals(req.body.password).run(req);
// eslint-disable-next-line @typescript-eslint/camelcase
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
await sanitize("email").normalizeEmail({ gmail_remove_dots: false }).run(req);

const errors = validationResult(req);

Expand Down Expand Up @@ -130,10 +130,10 @@ export const getAccount = (req: Request, res: Response) => {
* POST /account/profile
* Update profile information.
*/
export const postUpdateProfile = (req: Request, res: Response, next: NextFunction) => {
check("email", "Please enter a valid email address.").isEmail();
export const postUpdateProfile = async (req: Request, res: Response, next: NextFunction) => {
await check("email", "Please enter a valid email address.").isEmail().run(req);
// eslint-disable-next-line @typescript-eslint/camelcase
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
await sanitize("email").normalizeEmail({ gmail_remove_dots: false }).run(req);

const errors = validationResult(req);

Expand Down Expand Up @@ -168,9 +168,9 @@ export const postUpdateProfile = (req: Request, res: Response, next: NextFunctio
* POST /account/password
* Update current password.
*/
export const postUpdatePassword = (req: Request, res: Response, next: NextFunction) => {
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
check("confirmPassword", "Passwords do not match").equals(req.body.password);
export const postUpdatePassword = async (req: Request, res: Response, next: NextFunction) => {
await check("password", "Password must be at least 4 characters long").isLength({ min: 4 }).run(req);
await check("confirmPassword", "Passwords do not match").equals(req.body.password).run(req);

const errors = validationResult(req);

Expand Down Expand Up @@ -251,9 +251,9 @@ export const getReset = (req: Request, res: Response, next: NextFunction) => {
* POST /reset/:token
* Process the reset password request.
*/
export const postReset = (req: Request, res: Response, next: NextFunction) => {
check("password", "Password must be at least 4 characters long.").isLength({ min: 4 });
check("confirm", "Passwords must match.").equals(req.body.password);
export const postReset = async (req: Request, res: Response, next: NextFunction) => {
await check("password", "Password must be at least 4 characters long.").isLength({ min: 4 }).run(req);
await check("confirm", "Passwords must match.").equals(req.body.password).run(req);

const errors = validationResult(req);

Expand Down Expand Up @@ -326,10 +326,10 @@ export const getForgot = (req: Request, res: Response) => {
* POST /forgot
* Create a random token, then the send user an email with a reset link.
*/
export const postForgot = (req: Request, res: Response, next: NextFunction) => {
check("email", "Please enter a valid email address.").isEmail();
export const postForgot = async (req: Request, res: Response, next: NextFunction) => {
await check("email", "Please enter a valid email address.").isEmail().run(req);
// eslint-disable-next-line @typescript-eslint/camelcase
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
await sanitize("email").normalizeEmail({ gmail_remove_dots: false }).run(req);

const errors = validationResult(req);

Expand Down

0 comments on commit f052852

Please sign in to comment.