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
@@ -21,7 +21,7 @@ export class AbstractBuyOperation {
let quantity = _get(req, 'quantity');
this.quantity = quantity ? Number(quantity) : 1;
if (isNaN(this.quantity)) throw new BadRequest(this.i18n('invalidQuantity'));
if (this.quantity < 1 || !Number.isInteger(this.quantity)) throw new BadRequest(this.i18n('invalidQuantity'));
}
/**
+1 -1
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));