force build/unit amounts to be > 0
[browser-rts.git] / src / api.ts
index 87569fe59f10a6935c679a69663432998fc7bbf8..1c1aab03c98b9d93ad270277228ee765f535df37 100644 (file)
@@ -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) {