From 64b08c65bb5718e05024927920ad866a5c39613c Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 25 May 2022 16:02:47 -0400 Subject: [PATCH] force build/unit amounts to be > 0 --- src/api.ts | 6 ++++++ src/errors.ts | 1 + 2 files changed, 7 insertions(+) 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, } -- 2.25.1