Created
September 6, 2018 17:23
-
-
Save Xordal/78812561130530af8b6d7888ab3dd60e to your computer and use it in GitHub Desktop.
joi arrays validation
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
{ | |
"cart_id": 56, | |
"drugs": [ | |
{ | |
"id": 8, | |
"count": 2 | |
}, | |
{ | |
"id": 456, | |
"count": 0 | |
} | |
] | |
} |
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
const joi = require("joi"); | |
module.exports = { | |
batchUpdate: { | |
body: { | |
cart_id: joi | |
.number() | |
.integer() | |
.min(1), | |
drugs: joi.array().items( | |
joi.object().keys({ | |
id: joi | |
.number() | |
.integer() | |
.min(1), | |
count: joi | |
.number() | |
.integer() | |
.min(0) | |
}) | |
) | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment