-
Notifications
You must be signed in to change notification settings - Fork 8
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
Harsh Patel
committed
Oct 31, 2019
1 parent
d8b634a
commit b135286
Showing
9 changed files
with
200 additions
and
102 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
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 |
---|---|---|
|
@@ -566,12 +566,43 @@ function actionValidator(fieldLocation, actionFieldName) { | |
} | ||
|
||
|
||
/** | ||
* Validates that action field is a valid action from constants passed, and checks if corresponding new status is valid. | ||
* @param {"query" | "body" | "header" | "param"} fieldLocation The location where the field should be found. | ||
* @param {string} actionFieldName The name of the action that needs to be performed. | ||
* @param {string} statusFieldName The name of the action that needs to be performed. | ||
*/ | ||
function updateObjectValidator(fieldLocation, actionFieldName) { | ||
const updateObjectValue = setProperValidationChainBuilder(fieldLocation, actionFieldName, "Invalid update object string."); | ||
|
||
return updateObjectValue.exists() | ||
.withMessage("The update object string must exist.") | ||
.custom(updateObjectValidatorHelper).withMessage("The value must be a valid update object."); | ||
} | ||
|
||
function updateObjectValidatorHelper(update) { | ||
try { | ||
var updateObject = JSON.parse(update); | ||
|
||
if (updateObject && typeof updateObject === "object" && !("password" in updateObject)) { | ||
This comment has been minimized.
Sorry, something went wrong.
pierreTklein
Member
|
||
for (var key in updateObject) { | ||
var schemaPath = Models.Hacker.searchableField(key); | ||
This comment has been minimized.
Sorry, something went wrong.
pierreTklein
Member
|
||
if (!schemaPath) return false; | ||
} | ||
return true; | ||
} | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
function statusValidator(fieldLocation, statusFieldName) { | ||
const statusValue = setProperValidationChainBuilder(fieldLocation, statusFieldName, "Invalid status."); | ||
return statusValue.exists().withMessage("The status must exist!").custom((val, { | ||
req | ||
}) => { | ||
return Constants.CORRESPONDING_STATUSES[req.query.action].includes(val); | ||
return Constants.HACKER_STATUSES.includes(val); | ||
}).withMessage("The value must be a proper status.") | ||
} | ||
|
||
|
@@ -647,5 +678,6 @@ module.exports = { | |
enumValidator: enumValidator, | ||
routesValidator: routesValidator, | ||
actionValidator: actionValidator, | ||
statusValidator: statusValidator | ||
statusValidator: statusValidator, | ||
updateObjectValidator: updateObjectValidator, | ||
}; |
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.
Consider
===
over==