Commit 51d46068 authored by Karamel's avatar Karamel
Browse files

Add POST tax route.

parent cfced2c3
use \Pasteque\Server\Model\Tax;
use \Pasteque\Server\System\API\APICaller;
......@@ -25,3 +26,21 @@ $app->GET('/api/tax/{id}', function($request, $response, $args) {
return $response->withApiResult(APICaller::run($ptApp, 'tax', 'get', $args['id']));
/** Create or update a tax. If an id is set, it's an update. If not, it's a create. */
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$tax = Tax::loadFromId($tab['id'], $ptApp->getDao());
if ($tax == null) {
$tax = new Tax();
try {
$tax->merge($tab, $ptApp->getDao());
} catch (InvalidFieldException $e) {
return $response->reject($e);
return $response->withApiResult(APICaller::run($ptApp, 'tax', 'write',
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