diff --git a/server/src/routes/accounts.routes.ts b/server/src/routes/accounts.routes.ts index 8c9c6d19e3bd1150e1ea37095c2e5ef3b3eac29f..3acae1a19880112e3aa429e93eb55e79ecd04444 100644 --- a/server/src/routes/accounts.routes.ts +++ b/server/src/routes/accounts.routes.ts @@ -33,7 +33,12 @@ accountsRouter.get( //update account accountsRouter.patch( "/api/accounts/:id/", - handleValidationResult, //!! not working here + body("first_name").if(body("first_name").exists()).not().isEmpty(), + body("last_name").if(body("last_name").exists()).not().isEmpty(), + body("email").if(body("email").exists()).isEmail().normalizeEmail(), + body("role").if(body("role").exists()).isIn(["coordinator", "boatManager"]), + body("password").if(body("password").exists()).isLength({ min: 6 }), + handleValidationResult, validateToken, accountsControllers.updateAccount ); diff --git a/server/src/routes/user.routes.ts b/server/src/routes/user.routes.ts index 5e0f3b753fd1f52847b5ade32e1a0cdfcd705e99..3da97ed656ec45a61c98a7baca025bc112887feb 100644 --- a/server/src/routes/user.routes.ts +++ b/server/src/routes/user.routes.ts @@ -6,20 +6,21 @@ import { body } from "express-validator"; const userRouter = Router(); - +//show current user userRouter.get( "/api/user/", validateToken, userControllers.showCurrentUserController ); + +//update current user userRouter.patch( "/api/user/", - body("first_name").not().isEmpty(), - body("last_name").not().isEmpty(), - body("email").isEmail().normalizeEmail(), - body("role").isIn(["coordinator", "boatManager"]), - body("password").isLength({ min: 6 }), + body("first_name").if(body("first_name").exists()).not().isEmpty(), + body("last_name").if(body("last_name").exists()).not().isEmpty(), + body("email").if(body("email").exists()).isEmail().normalizeEmail(), + body("password").if(body("password").exists()).isLength({ min: 6 }), handleValidationResult, validateToken, userControllers.updateCurrentUser