Commit dcd426b2 authored by Karamel's avatar Karamel
Browse files

Add missing error responses with invalid input in routes

parent c2ec7229
......@@ -99,7 +99,11 @@ $app->POST('/api/cashregister',
return $response->reject($e, 'Reference is already taken');
}
}
$cr->merge($tab, $ptApp->getDao());
try {
$cr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'cashregister',
'write', $cr));
});
......@@ -126,7 +130,11 @@ $app->PUT('/api/cashregister/{reference}',
return $response->reject($e, 'Reference is already taken');
}
$cr = new CashRegister();
$cr->merge($tab, $ptApp->getDao());
try {
$cr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'cashregister',
'write', $cr));
});
......@@ -153,7 +161,11 @@ $app->PATCH('/api/cashregister/{reference}',
return $response->reject($e, 'Reference is already taken');
}
}
$cr->merge($tab, $ptApp->getDao());
try {
$cr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'cashregister',
'write', $cr));
});
......@@ -42,7 +42,11 @@ $app->POST('/api/currency',
return $response->reject($e, 'Reference is already taken');
}
}
$curr->merge($tab, $ptApp->getDao());
try {
$curr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write',
$curr));
});
......@@ -69,7 +73,11 @@ $app->PUT('/api/currency/{reference}',
return $response->reject($e, 'Reference is already taken');
}
$curr = new Currency();
$curr->merge($tab, $ptApp->getDao());
try {
$curr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write',
$curr));
});
......@@ -91,7 +99,11 @@ $app->PATCH('/api/currency/{reference}',
$e = new RecordNotFoundException(Currency::class, $loadKey);
return $response->notFound($e, 'No currency found.');
}
$curr->merge($tab, $ptApp->getDao());
try {
$curr->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
if ($tab['reference'] !== $args['reference']) {
$otherCurr = Currency::structLoad($tab, $ptApp->getDao());
if ($otherCurr !== null) {
......
......@@ -110,7 +110,11 @@ function oldApiCustomer($ptApp, $response, $jsonCusts) {
if ($cust === null) {
$cust = new Customer();
}
$cust->merge($strC, $ptApp->getDao());
try {
$cust->merge($strC, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
$customers[] = $cust;
// There is no expireDate in the form from Android, so ignore it.
}
......
<?php
use \Pasteque\Server\Exception\InvalidFieldException;
use \Pasteque\Server\Model\DiscountProfile;
use \Pasteque\Server\System\API\APICaller;
......@@ -50,7 +51,11 @@ $app->POST('/api/discountprofile',
if ($profile === null) {
$profile = new DiscountProfile();
}
$profile->merge($tab, $ptApp->getDao());
try {
$profile->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile',
'write', $profile));
});
......@@ -539,7 +539,11 @@ function fiscal_importTickets($ptApp, $data) {
// will check agains snapshots anyway.
$fTkt = new FiscalTicket();
}
$fTkt->merge($tkt, $ptApp->getDao());
try {
$fTkt->merge($tkt, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
$tkts[] = $fTkt;
}
$apiResult = APICaller::run($ptApp, 'fiscal', 'batchImport', [$tkts]);
......
<?php
use \Pasteque\Server\Exception\InvalidFieldException;
use \Pasteque\Server\Model\Floor;
use \Pasteque\Server\System\API\APICaller;
use \Pasteque\Server\System\API\APIResult;
......@@ -20,7 +21,11 @@ $app->POST('/api/places',
if ($floor === null) {
$floor = new Floor();
}
$floor->merge($jsFloor, $ptApp->getDao());
try {
$floor->merge($jsFloor, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
$floors[] = $floor;
}
return $response->withApiResult(APICaller::run($ptApp, 'place', 'write',
......
......@@ -26,7 +26,11 @@ $app->POST('/api/resource',
if ($res === null) {
$res = new Resource();
}
$res->merge($tab, $ptApp->getDao());
try {
$res->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'resource', 'write',
$res));
});
......@@ -50,7 +54,11 @@ $app->PATCH('/api/resource/{label}',
return $response->reject($e);
}
}
$res->merge($tab, $ptApp->getDao());
try {
$res->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'resource', 'write',
$res));
});
......
<?php
use \Pasteque\Server\Exception\InvalidFieldException;
use \Pasteque\Server\Model\Role;
use \Pasteque\Server\System\API\APICaller;
......@@ -40,7 +41,11 @@ $app->POST('/api/role',
if ($role === null) {
$role = new Role();
}
$role->merge($tab, $ptApp->getDao());
try {
$role->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
}
return $response->withApiResult(APICaller::run($ptApp, 'role', 'write',
$role));
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment