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:
@@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user