Improved number validation (#11131)

* fix(purchasing): more number validation

* test(purchasing): add error cases
Also refactor NaN check and create client mixin

* fix(purchasing): cover "purchase" cases
This commit is contained in:
Sabe Jones
2019-04-23 15:19:49 -05:00
committed by GitHub
parent 9f09a0396b
commit 6f7cd96e9f
9 changed files with 109 additions and 10 deletions

View File

@@ -73,7 +73,7 @@ module.exports = function purchase (user, req = {}, analytics) {
let key = get(req.params, 'key');
let quantity = req.quantity ? Number(req.quantity) : 1;
if (isNaN(quantity)) throw new BadRequest(i18n.t('invalidQuantity', req.language));
if (quantity < 1 || !Number.isInteger(quantity)) throw new BadRequest(i18n.t('invalidQuantity', req.language));
if (!type) {
throw new BadRequest(i18n.t('typeRequired', req.language));