@momsfriendlydevco/cowboy 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/middleware/validate.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import joyful from '@momsfriendlydevco/joyful';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Run a Joi / Joyful validation function against a specific subkey within `req
|
|
5
|
+
*
|
|
6
|
+
* @param {String} subkey The subkey to run against
|
|
7
|
+
* @param {Function|Object} Callback to use with Joyful to validate with
|
|
8
|
+
* @returns {Void} Either a successful middleware cycle (if validatio succeeds) or a call to `res.status(400)` if failed
|
|
9
|
+
*/
|
|
3
10
|
export default function CowboyMiddlewareValidate(subkey, validator) {
|
|
4
11
|
return (req, res) => {
|
|
5
|
-
let joyfulResult = joyful(
|
|
6
|
-
[subkey]: validator,
|
|
7
|
-
});
|
|
12
|
+
let joyfulResult = joyful(req[subkey], validator);
|
|
8
13
|
|
|
9
14
|
if (joyfulResult !== true) { // Failed body validation?
|
|
10
15
|
return res
|