add value host email and password from db global settings table

This commit is contained in:
arifal
2025-01-27 19:46:45 +07:00
parent 82ab44cfb6
commit 8b77e748ca
7 changed files with 103 additions and 17 deletions

View File

@@ -3,6 +3,7 @@
namespace App;
use App\Enums\ImportDatasourceStatus;
use App\Models\GlobalSetting;
use App\Models\ImportDatasource;
use App\Models\PbgTaskIndexIntegrations;
use App\Models\PbgTaskPrasarana;
@@ -17,18 +18,20 @@ class ServiceSIMBG
use GlobalApiResponse;
private $email;
private $password;
private $simbg_host;
/**
* Create a new class instance.
*/
public function __construct()
{
$this->email = $_ENV['SIMBG_EMAIL'];
$this->password = $_ENV['SIMBG_PASSWORD'];
$this->email = trim((string) GlobalSetting::where('key','SIMBG_EMAIL')->first()->value);
$this->password = trim((string) GlobalSetting::where('key','SIMBG_PASSWORD')->first()->value);
$this->simbg_host = trim((string)GlobalSetting::where('key','SIMBG_HOST')->first()->value);
}
public function getToken(){
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']);
$url = "api/user/v1/auth/login/";
$clientHelper = new ServiceClient($this->simbg_host);
$url = "/api/user/v1/auth/login/";
$body = [
'email' => $this->email,
'password' => $this->password,
@@ -44,8 +47,8 @@ class ServiceSIMBG
public function syncIndexIntegration($uuid)
{
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']);
$url = "api/pbg/v1/detail/" . $uuid . "/retribution/indeks-terintegrasi/";
$clientHelper = new ServiceClient($this->simbg_host);
$url = "/api/pbg/v1/detail/" . $uuid . "/retribution/indeks-terintegrasi/";
$resToken = $this->getToken();
if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) {
@@ -93,7 +96,7 @@ class ServiceSIMBG
public function syncTaskList()
{
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']);
$clientHelper = new ServiceClient($this->simbg_host);
$resToken = $this->getToken();
// create log import datasource
@@ -118,7 +121,7 @@ class ServiceSIMBG
'type' => 'task',
]);
$url = "api/pbg/v1/list/?" . $queryParams;
$url = "/api/pbg/v1/list/?" . $queryParams;
$headers = ['Authorization' => "Bearer " . $apiToken];
$initialResponse = $clientHelper->get($url, $headers);
@@ -143,7 +146,7 @@ class ServiceSIMBG
'type' => 'task',
]);
$url = "api/pbg/v1/list/?" . $queryParams;
$url = "/api/pbg/v1/list/?" . $queryParams;
$response = $clientHelper->get($url, $headers);
if (empty($response->original['data']['data'])) {
@@ -221,7 +224,7 @@ class ServiceSIMBG
public function syncTaskDetailSubmit($uuid)
{
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']);
$clientHelper = new ServiceClient($this->simbg_host);
$resToken = $this->getToken();
if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) {
@@ -231,7 +234,7 @@ class ServiceSIMBG
}
$apiToken = $resToken->original['data']['token']['access'];
$url = "api/pbg/v1/detail/" . $uuid . "/retribution/submit/";
$url = "/api/pbg/v1/detail/" . $uuid . "/retribution/submit/";
$headers = [
'Authorization' => "Bearer " . $apiToken,
];