diff --git a/build/api/module/motheure.php b/build/api/module/motheure.php index 29b5e92..6119baf 100644 --- a/build/api/module/motheure.php +++ b/build/api/module/motheure.php @@ -85,12 +85,17 @@ /* (1) Check if entry exists ---------------------------------------------------------*/ /* (1) Check if there is an entry for the current machine */ - $already_exists = is_array(Table::get('motheure') + $fetched = Table::get('motheure') ->unique() ->select('id_motheure') ->select('id_machine') + ->select('count') ->whereIdMachine($_SESSION['SATS']['id']) - ->fetch()); + ->fetch(); + + /* (2) Set variable to ease process */ + $already_exists = is_array($fetched); + /* (2) If does not exist, create entry @@ -115,11 +120,8 @@ /* (1) Update entry */ $updated = Table::get('motheure') - ->unique() ->whereIdMachine($_SESSION['SATS']['id']) - ->edit([ - 'count' => $count - ]); + ->edit([ 'count' => $count + $fetched['count'] ]); /* (2) Propagate error */ return [ 'error' => ($updated) ? new Error(Err::Success) : new Error(Err::RepoError) ];