Last active
October 19, 2018 17:42
-
-
Save jirevwe/ec8ec0759f9884c446441c8f7de90b62 to your computer and use it in GitHub Desktop.
Params not valid
This file contains hidden or 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
exports.paramsNotValid = (...args) => args | |
.map(param => param !== undefined && param != null && param !== '') | |
.includes(false) |
This file contains hidden or 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
/** | |
* @method POST /api/projects | |
* @description creates a project | |
* @param name project name | |
* @param description project description | |
* @param beneficiary the charity that benefits from the project | |
* @param image the project's cover image | |
* @param goal the target amount to be raised by the project | |
* @param category the project category | |
*/ | |
router.post('/', authorization, async (r, s) => { | |
try { | |
const not_valid = await checkParamsValid( | |
r.body.name, | |
r.body.description, | |
r.body.beneficiary, | |
r.body.goal, | |
r.body.category | |
) | |
if (not_valid) { | |
return s.status(412).json({ | |
status: 'Precondition Failed', | |
message: 'Some parameters should not be null or be empty' | |
}) | |
} | |
const project = await Project.create(r.body) | |
return s.status(200).json({ | |
status: 'Project Created', | |
data: project | |
}) | |
} catch (error) { | |
return s.status(400).json({ | |
status: 'Failed', | |
message: error | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment