Add api user name to create source for warranty and warranty_api_log. #579

This commit is contained in:
Korina Cordero 2021-06-10 07:20:02 +00:00
parent 31f43aea39
commit 3937b73454
3 changed files with 46 additions and 3 deletions

View file

@ -2,6 +2,8 @@
namespace App\Controller\CAPI; namespace App\Controller\CAPI;
use Catalyst\APIBundle\Entity\User as APIUser;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
@ -315,7 +317,11 @@ class CustomerWarrantyController extends APIController
'invoice' => $req->request->get('invoice'), 'invoice' => $req->request->get('invoice'),
]; ];
$action = 'create/update'; $action = 'create/update';
$source = WarrantySource::CAPI;
// get the api_user that made the call so that it gets added to the source
// source becomes CAPI_USER_<insert name of api user here>
$username = $this->getAPIUsername($em, $user_id);
$source = 'CAPI_USER_' . $username;
error_log('SOURCE: ' . $source); error_log('SOURCE: ' . $source);
@ -582,4 +588,15 @@ class CustomerWarrantyController extends APIController
$rt->sendSMS($clean_num, 'MOTOLITE', $message); $rt->sendSMS($clean_num, 'MOTOLITE', $message);
} }
protected function getAPIUsername($em, $user_id)
{
$api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]);
$username = '';
foreach ($api_user_result as $api_user)
{
$username = $api_user->getName();
}
return $username;
}
} }

View file

@ -2,6 +2,8 @@
namespace App\Controller\CAPI; namespace App\Controller\CAPI;
use Catalyst\APIBundle\Entity\User as APIUser;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
@ -191,7 +193,12 @@ class WarrantyController extends APIController
'mobile_number' => $mnum, 'mobile_number' => $mnum,
]; ];
$action = 'create'; $action = 'create';
$source = WarrantySource::CAPI;
// get the api_user that made the call so that it gets added to the source
// source becomes CAPI_USER_<insert name of api user here>
$username = $this->getAPIUsername($em, $user_id);
$source = 'CAPI_USER_' . $username;
$msg = $this->checkRequiredParameters($req, $params); $msg = $this->checkRequiredParameters($req, $params);
error_log('msg - ' . $msg); error_log('msg - ' . $msg);
@ -322,7 +329,12 @@ class WarrantyController extends APIController
'id' => $id, 'id' => $id,
]; ];
$action = 'claim'; $action = 'claim';
$source = WarrantySource::CAPI;
// get the api_user that made the call so that it gets added to the source
// source becomes CAPI_USER_<insert name of api user here>
$username = $this->getAPIUsername($em, $user_id);
$source = 'CAPI_USER_' . $username;
$msg = $this->checkRequiredParameters($req, $params); $msg = $this->checkRequiredParameters($req, $params);
if ($msg) if ($msg)
@ -777,4 +789,16 @@ class WarrantyController extends APIController
return $customers; return $customers;
} }
protected function getAPIUsername($em, $user_id)
{
$api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]);
$username = '';
foreach ($api_user_result as $api_user)
{
$username = $api_user->getName();
}
return $username;
}
} }

View file

@ -10,6 +10,7 @@ class WarrantySource extends NameValue
const BULK_UPLOAD = 'bulk_upload'; const BULK_UPLOAD = 'bulk_upload';
const MOBILE = 'mobile'; const MOBILE = 'mobile';
const COMMAND = 'command'; const COMMAND = 'command';
const UNKNOWN = 'unknown';
const COLLECTION = [ const COLLECTION = [
'capi' => 'Third Party API', 'capi' => 'Third Party API',
@ -18,6 +19,7 @@ class WarrantySource extends NameValue
'bulk_upload' => 'Bulk Upload', 'bulk_upload' => 'Bulk Upload',
'mobile' => 'Mobile API', 'mobile' => 'Mobile API',
'command' => 'Command', 'command' => 'Command',
'unknown' => 'Unknown',
]; ];
} }