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

Add POST tax route.

parent cfced2c3
<?php
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. */
$app->POST('/api/tax',
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',
$tax));
});
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