mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-01-06 12:50:11 -06:00
#276 Increment amount
This commit is contained in:
@@ -179,6 +179,7 @@ return [
|
||||
array('/api/inventory/fetch', 'ANY', 'api@fetch_inventory'),
|
||||
array('/api/inventory/add', 'ANY', 'api@add_inventory_item'),
|
||||
array('/api/inventory/edit', 'ANY', 'api@edit_inventory_item'),
|
||||
array('/api/inventory/amount/inc', 'ANY', 'api@inc_inventory_item'),
|
||||
array('/api/chat/message/add', 'ANY', 'api@add_chat_message'),
|
||||
|
||||
/** Backup Controller */
|
||||
|
||||
@@ -617,6 +617,31 @@ class ApiController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /api/inventory/amount/inc
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\JsonHandler
|
||||
*/
|
||||
public static function inc_inventory_item($request)
|
||||
{
|
||||
try {
|
||||
$item = $request->params()->query('item', null);
|
||||
|
||||
$amount = InventoryModel::incAmount($item, true);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'amount' => $amount
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /api/chat/message/add
|
||||
*
|
||||
|
||||
@@ -145,14 +145,15 @@ class InventoryModel extends \Asatru\Database\Model {
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $api
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function incAmount($id)
|
||||
public static function incAmount($id, $api = false)
|
||||
{
|
||||
try {
|
||||
$user = UserModel::getAuthUser();
|
||||
if (!$user) {
|
||||
if ((!$user) && (!$api)) {
|
||||
throw new \Exception('Invalid user');
|
||||
}
|
||||
|
||||
@@ -164,10 +165,12 @@ class InventoryModel extends \Asatru\Database\Model {
|
||||
$amount = $row->get('amount') + 1;
|
||||
|
||||
static::raw('UPDATE `' . self::tableName() . '` SET amount = ?, last_edited_user = ?, last_edited_date = CURRENT_TIMESTAMP WHERE id = ?', [
|
||||
$amount, $user->get('id'), $row->get('id')
|
||||
$amount, (($user) ? $user->get('id') : 0), $row->get('id')
|
||||
]);
|
||||
|
||||
LogModel::addLog($user->get('id'), 'inventory', 'increment_inventory_item', $row->get('name'), url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
if (!$api) {
|
||||
LogModel::addLog($user->get('id'), 'inventory', 'increment_inventory_item', $row->get('name'), url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
}
|
||||
|
||||
return $amount;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user