Add log for warranty from app. #717
This commit is contained in:
parent
36ad7a28c2
commit
b1d7777726
4 changed files with 194 additions and 4 deletions
|
|
@ -277,6 +277,11 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
|
|
||||||
|
# warranty logger for app
|
||||||
|
App\Service\WarrantyLogger:
|
||||||
|
arguments:
|
||||||
|
$em: "@doctrine.orm.entity_manager"
|
||||||
|
|
||||||
# promo logger
|
# promo logger
|
||||||
App\Service\PromoLogger:
|
App\Service\PromoLogger:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ use App\Service\RiderTracker;
|
||||||
use App\Service\MapTools;
|
use App\Service\MapTools;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
use App\Service\RiderAssignmentHandlerInterface;
|
use App\Service\RiderAssignmentHandlerInterface;
|
||||||
use App\Service\WarrantyAPILogger;
|
use App\Service\WarrantyLogger;
|
||||||
use App\Service\PromoLogger;
|
use App\Service\PromoLogger;
|
||||||
use App\Service\HubSelector;
|
use App\Service\HubSelector;
|
||||||
use App\Service\HubDistributor;
|
use App\Service\HubDistributor;
|
||||||
|
|
@ -3578,7 +3578,7 @@ class APIController extends Controller implements LoggedController
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt,
|
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt,
|
||||||
TranslatorInterface $trans, WarrantyAPILogger $logger)
|
TranslatorInterface $trans, WarrantyLogger $logger)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -3608,7 +3608,7 @@ class APIController extends Controller implements LoggedController
|
||||||
'last_name' => $req->request->get('last_name'),
|
'last_name' => $req->request->get('last_name'),
|
||||||
'date_purchase' => $req->request->get('date_purchase'),
|
'date_purchase' => $req->request->get('date_purchase'),
|
||||||
];
|
];
|
||||||
$action = 'create';
|
$action = 'create/update';
|
||||||
$source = WarrantySource::MOBILE;
|
$source = WarrantySource::MOBILE;
|
||||||
|
|
||||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||||
|
|
@ -3978,6 +3978,8 @@ class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Warranty registered to a vehicle not in your list of vehicles.');
|
->setErrorMessage('Warranty registered to a vehicle not in your list of vehicles.');
|
||||||
|
// set action to update
|
||||||
|
$action = 'update';
|
||||||
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
150
src/Entity/WarrantyLog.php
Normal file
150
src/Entity/WarrantyLog.php
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="warranty_log")
|
||||||
|
*/
|
||||||
|
class WarrantyLog
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// date created
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime")
|
||||||
|
*/
|
||||||
|
protected $date_create;
|
||||||
|
|
||||||
|
// user that created warranty
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=32)
|
||||||
|
*/
|
||||||
|
protected $api_user;
|
||||||
|
|
||||||
|
// data sent
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="json")
|
||||||
|
*/
|
||||||
|
protected $data_sent;
|
||||||
|
|
||||||
|
// errors
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
*/
|
||||||
|
protected $error;
|
||||||
|
|
||||||
|
// action
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=20)
|
||||||
|
*/
|
||||||
|
protected $action;
|
||||||
|
|
||||||
|
// source
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=30)
|
||||||
|
*/
|
||||||
|
protected $source;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->date_create = new DateTime();
|
||||||
|
$this->error = '';
|
||||||
|
$this->data_sent = [];
|
||||||
|
$this->action = '';
|
||||||
|
$this->source = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateCreate(DateTime $date_create)
|
||||||
|
{
|
||||||
|
$this->date_create = $date_create;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateCreate()
|
||||||
|
{
|
||||||
|
return $this->date_create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setApiUser($api_user)
|
||||||
|
{
|
||||||
|
$this->api_user = $api_user;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiUser()
|
||||||
|
{
|
||||||
|
return $this->api_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addDataSent($id, $value)
|
||||||
|
{
|
||||||
|
$this->data_sent[$id] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDataSent($data_sent)
|
||||||
|
{
|
||||||
|
$this->data_sent = $data_sent;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDataSent($id)
|
||||||
|
{
|
||||||
|
// return null if we don't have it
|
||||||
|
if (!isset($this->data_sent[$id]))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return $this->data_sent[$id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getError()
|
||||||
|
{
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setError($error)
|
||||||
|
{
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAction($action)
|
||||||
|
{
|
||||||
|
$this->action = $action;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAction()
|
||||||
|
{
|
||||||
|
return $this->action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSource($source)
|
||||||
|
{
|
||||||
|
$this->source = $source;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
33
src/Service/WarrantyLogger.php
Normal file
33
src/Service/WarrantyLogger.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Entity\WarrantyLog;
|
||||||
|
|
||||||
|
class WarrantyLogger
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logWarrantyInfo($log_data, $error, $user_id, $action, $source)
|
||||||
|
{
|
||||||
|
$log_entry = new WarrantyAPILog();
|
||||||
|
|
||||||
|
$log_entry->setApiUser($user_id)
|
||||||
|
->setError($error)
|
||||||
|
->setDataSent($log_data)
|
||||||
|
->setAction($action)
|
||||||
|
->setSource($source);
|
||||||
|
|
||||||
|
$this->em->persist($log_entry);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue