add transaction

main
nocode 1 year ago
parent 687ef5b28e
commit 91dd62561e
  1. 13
      app/Http/Controllers/Api/AuthApiController.php

@ -12,6 +12,7 @@ use App\Models\Agent;
use App\Models\AgentUser; use App\Models\AgentUser;
use App\Http\Requests\Api\RegisterApiRequest; use App\Http\Requests\Api\RegisterApiRequest;
use App\Http\Requests\Api\LoginApiRequest; use App\Http\Requests\Api\LoginApiRequest;
use Illuminate\Support\Facades\DB;
class AuthApiController extends BaseAuthApiController class AuthApiController extends BaseAuthApiController
{ {
@ -113,13 +114,14 @@ class AuthApiController extends BaseAuthApiController
$dataInsert = $this->transformRegisterData($request->all()); $dataInsert = $this->transformRegisterData($request->all());
DB::beginTransaction();
if (!empty($dataInsert)) { if (!empty($dataInsert)) {
if (!empty($checkUserAgent->agent_id)) { if (!empty($checkUserAgent->agent_id)) {
$agentParent = Agent::find($checkUserAgent->agent_id); $agentParent = Agent::find($checkUserAgent->agent_id);
$grantParent = $agentParent->grant; $grantParent = $agentParent->grant;
$parentPath = $agentParent->parent_path ?? null; $parentPath = $agentParent->parent_path ?? null;
} }
try {
$userId = \App\Models\User::insertGetId($dataInsert); $userId = \App\Models\User::insertGetId($dataInsert);
if ($userId) { if ($userId) {
@ -148,12 +150,19 @@ class AuthApiController extends BaseAuthApiController
} }
; ;
} }
DB::commit();
return response()->json(['status' => true, 'msg' => $this->getMessageReponse(1)]); return response()->json(['status' => true, 'msg' => $this->getMessageReponse(1)]);
} catch (\Exception $e) {
DB::rollBack();
}
} }
return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]);
} }
public function addParentPath($parentPath, $userIdAdd){ public function addParentPath($parentPath, $userIdAdd)
{
return rtrim($parentPath, '-') . '-' . $userIdAdd . '-'; return rtrim($parentPath, '-') . '-' . $userIdAdd . '-';
} }
public function generateNewCode($code) public function generateNewCode($code)

Loading…
Cancel
Save