From: xangelo Date: Wed, 25 May 2022 20:02:47 +0000 (-0400) Subject: force build/unit amounts to be > 0 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=64b08c65bb5718e05024927920ad866a5c39613c;p=browser-rts.git force build/unit amounts to be > 0 --- diff --git a/src/api.ts b/src/api.ts index 87569fe..1c1aab0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -258,6 +258,9 @@ server.post<{ const city = await cityRepo.getUsersCity(account.id); const amount = parseInt(req.body.amount, 10); + if(amount < 1) { + throw new BadInputError('Please specify an amount > 0', ERROR_CODE.INVALID_AMOUNT); + } const building = await cityRepo.buildingRepository.findBySlug(req.body.building_type); if(!building) { @@ -281,6 +284,9 @@ server.post<{ const city = await cityRepo.getUsersCity(acct.id); const amount = parseInt(req.body.amount, 10); + if(amount < 1) { + throw new BadInputError('Please specify an amount > 0', ERROR_CODE.INVALID_AMOUNT); + } const unit = await cityRepo.unitRepository.findBySlug(req.body.type); if(!unit) { diff --git a/src/errors.ts b/src/errors.ts index ff5ef30..1a9b605 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -47,6 +47,7 @@ export const ERROR_CODE = { NO_CITY: 2000, INSUFFICIENT_RESOURCE: 3000, INVALID_BUILDING: 4000, + INVALID_AMOUNT: 6000, INVALID_UNIT: 5000, DUPLICATE_CACHE_KEY: 900, }