Home
/
browser-rts.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2266b58
)
force build/unit amounts to be > 0
author
xangelo
<git@xangelo.ca>
Wed, 25 May 2022 20:02:47 +0000
(16:02 -0400)
committer
xangelo
<git@xangelo.ca>
Wed, 25 May 2022 20:02:47 +0000
(16:02 -0400)
src/api.ts
patch
|
blob
|
history
src/errors.ts
patch
|
blob
|
history
diff --git
a/src/api.ts
b/src/api.ts
index 87569fe59f10a6935c679a69663432998fc7bbf8..1c1aab03c98b9d93ad270277228ee765f535df37 100644
(file)
--- 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);
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) {
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);
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) {
const unit = await cityRepo.unitRepository.findBySlug(req.body.type);
if(!unit) {
diff --git
a/src/errors.ts
b/src/errors.ts
index ff5ef308b670d98b9b60a380d7f5fe4e1b9dbe0f..1a9b605dc7f45940c8f50a12cda54ab90d0b2557 100644
(file)
--- 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,
NO_CITY: 2000,
INSUFFICIENT_RESOURCE: 3000,
INVALID_BUILDING: 4000,
+ INVALID_AMOUNT: 6000,
INVALID_UNIT: 5000,
DUPLICATE_CACHE_KEY: 900,
}
INVALID_UNIT: 5000,
DUPLICATE_CACHE_KEY: 900,
}