Add source to WarrantyAPILog. #555
This commit is contained in:
parent
42c2b52690
commit
7ec5ba439c
6 changed files with 2964 additions and 1256 deletions
4117
composer.lock
generated
4117
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -33,6 +33,7 @@ use App\Ramcar\WarrantyClass;
|
|||
use App\Ramcar\WarrantyStatus;
|
||||
use App\Ramcar\FuelType;
|
||||
use App\Ramcar\VehicleStatusCondition;
|
||||
use App\Ramcar\WarrantySource;
|
||||
|
||||
use DateTime;
|
||||
|
||||
|
|
@ -74,14 +75,14 @@ class CustomerWarrantyController extends APIController
|
|||
return $missing;
|
||||
}
|
||||
|
||||
protected function checkRequiredParams(Request $req, $params, $logger, $log_data, $user_id, $action)
|
||||
protected function checkRequiredParams(Request $req, $params, $logger, $log_data, $user_id, $action, $source)
|
||||
{
|
||||
// check required parameters
|
||||
$missing = $this->checkMissingParameters($req, $params);
|
||||
if (count($missing) > 0)
|
||||
{
|
||||
$miss_string = implode(', ', $missing);
|
||||
$logger->logWarrantyInfo($log_data, 'Missing parameter(s): ' . $miss_string, $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Missing parameter(s): ' . $miss_string, $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Missing parameter(s): ' . $miss_string);
|
||||
}
|
||||
|
||||
|
|
@ -105,9 +106,11 @@ class CustomerWarrantyController extends APIController
|
|||
'serial' => $serial,
|
||||
];
|
||||
$action = 'check';
|
||||
$source = WarrantySource::CAPI;
|
||||
|
||||
// check required parameters
|
||||
$required_params = [];
|
||||
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action);
|
||||
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
|
||||
if (!$res)
|
||||
return $res;
|
||||
|
||||
|
|
@ -316,13 +319,16 @@ class CustomerWarrantyController extends APIController
|
|||
'invoice' => $req->request->get('invoice'),
|
||||
];
|
||||
$action = 'create/update';
|
||||
$source = WarrantySource::CAPI;
|
||||
|
||||
error_log('SOURCE: ' . $source);
|
||||
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'plate_num'
|
||||
];
|
||||
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action);
|
||||
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
|
||||
|
||||
if (!$res)
|
||||
return $res;
|
||||
|
|
@ -338,7 +344,8 @@ class CustomerWarrantyController extends APIController
|
|||
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
||||
|
||||
// do actual registering
|
||||
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename, $logger, $log_data, $user_id, $action);
|
||||
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
|
||||
$logger, $log_data, $user_id, $action, $source);
|
||||
|
||||
// flush to db
|
||||
$em->flush();
|
||||
|
|
@ -380,7 +387,7 @@ class CustomerWarrantyController extends APIController
|
|||
}
|
||||
|
||||
protected function updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
|
||||
$logger, $log_data, $user_id, $action)
|
||||
$logger, $log_data, $user_id, $action, $source)
|
||||
{
|
||||
$plate_num = $this->cleanPlateNumber($req->request->get('plate_num'));
|
||||
|
||||
|
|
@ -389,7 +396,7 @@ class CustomerWarrantyController extends APIController
|
|||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||
if ($warr_serial == null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid warranty serial code..', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid warranty serial code..', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Invalid warranty serial code.');
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +412,7 @@ class CustomerWarrantyController extends APIController
|
|||
|
||||
if ($plate_num != $warr_plate_num)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Plate number does not match vehicle registered to warranty.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Plate number does not match vehicle registered to warranty.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +438,7 @@ class CustomerWarrantyController extends APIController
|
|||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($sap_bty == null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Cound not find battery entry for warranty.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Cound not find battery entry for warranty.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Could not find battery entry for warranty.');
|
||||
}
|
||||
}
|
||||
|
|
@ -444,7 +451,7 @@ class CustomerWarrantyController extends APIController
|
|||
$vehicle = $em->getRepository(Vehicle::class)->find($vmake_id);
|
||||
if ($vehicle == null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Could not find vehicle specified for warranty.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Could not find vehicle specified for warranty.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Could not find vehicle specified for warranty.');
|
||||
}
|
||||
}
|
||||
|
|
@ -461,7 +468,7 @@ class CustomerWarrantyController extends APIController
|
|||
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
|
||||
if (!$date_pur_cust)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid date format for date of purchase.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid date format for date of purchase.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
||||
}
|
||||
}
|
||||
|
|
@ -538,7 +545,7 @@ class CustomerWarrantyController extends APIController
|
|||
|
||||
$em->persist($warr);
|
||||
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||
|
||||
// TODO: check if we need to do anyting else
|
||||
$data = [];
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use App\Ramcar\WarrantyClass;
|
|||
use App\Ramcar\WarrantyStatus;
|
||||
use App\Ramcar\FuelType;
|
||||
use App\Ramcar\VehicleStatusCondition;
|
||||
use App\Ramcar\WarrantySource;
|
||||
|
||||
use DateTime;
|
||||
|
||||
|
|
@ -189,12 +190,13 @@ class WarrantyController extends APIController
|
|||
'mobile_number' => $mnum,
|
||||
];
|
||||
$action = 'create';
|
||||
$source = WarrantySource::CAPI;
|
||||
|
||||
$msg = $this->checkRequiredParameters($req, $params);
|
||||
error_log('msg - ' . $msg);
|
||||
if ($msg)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
|
||||
return new APIResponse(false, $msg);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +209,7 @@ class WarrantyController extends APIController
|
|||
$date_expire = DateTime::createFromFormat('Ymd', $date_expire_string);
|
||||
if ($date_expire === false)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_expire.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_expire.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Wrong date format: date_expire.');
|
||||
}
|
||||
|
||||
|
|
@ -215,14 +217,14 @@ class WarrantyController extends APIController
|
|||
$date_pur = DateTime::createFromFormat('Ymd', $date_pur_string);
|
||||
if ($date_pur === false)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_purchase', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_purchase', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Wrong date format: date_purchase.');
|
||||
}
|
||||
|
||||
// valid warranty class
|
||||
if (!WarrantyClass::validate($warr_class))
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid warranty class.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid warranty class.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Invalid warranty class.');
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +232,7 @@ class WarrantyController extends APIController
|
|||
$plate = Warranty::cleanPlateNumber($plate);
|
||||
if (!$plate)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid plate number.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid plate number.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +245,7 @@ class WarrantyController extends APIController
|
|||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid battery SKU.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Invalid battery SKU.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +285,7 @@ class WarrantyController extends APIController
|
|||
}
|
||||
catch (UniqueConstraintViolationException $e)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Duplicate serial encountered.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Duplicate serial encountered.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Duplicate serial encountered.');
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +295,7 @@ class WarrantyController extends APIController
|
|||
];
|
||||
|
||||
// log creation of warranty data
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||
|
||||
return new APIResponse(true, 'Warranty registered.', $data);
|
||||
}
|
||||
|
|
@ -317,11 +319,12 @@ class WarrantyController extends APIController
|
|||
'id' => $id,
|
||||
];
|
||||
$action = 'claim';
|
||||
$source = WarrantySource::CAPI;
|
||||
|
||||
$msg = $this->checkRequiredParameters($req, $params);
|
||||
if ($msg)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
|
||||
return new APIResponse(false, $msg);
|
||||
}
|
||||
|
||||
|
|
@ -329,14 +332,14 @@ class WarrantyController extends APIController
|
|||
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||
if ($warr == null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'No warranty found with that id.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'No warranty found with that id.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||
}
|
||||
|
||||
// warranty is not active
|
||||
if (!$warr->canClaim())
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Warranty is not active.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Warranty is not active.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Warranty is not active.');
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +349,7 @@ class WarrantyController extends APIController
|
|||
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||
if ($check_warr != null)
|
||||
{
|
||||
$logger->logWarrantyInfo($log_data, 'Serial for replacement has already been used.', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, 'Serial for replacement has already been used.', $user_id, $action, $source);
|
||||
return new APIResponse(false, 'Serial for replacement has already been used.');
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +377,7 @@ class WarrantyController extends APIController
|
|||
$em->flush();
|
||||
|
||||
// TODO: claim log
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action);
|
||||
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||
|
||||
return new APIResponse(true, 'Warranty claimed successfully.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,11 +53,19 @@ class WarrantyAPILog
|
|||
*/
|
||||
protected $action;
|
||||
|
||||
// source
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
$this->errors = new ArrayCollection();
|
||||
$this->all_data = [];
|
||||
$this->action = '';
|
||||
$this->source = '';
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -142,4 +150,14 @@ class WarrantyAPILog
|
|||
return $this->action;
|
||||
}
|
||||
|
||||
public function setSource($source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
20
src/Ramcar/WarrantySource.php
Normal file
20
src/Ramcar/WarrantySource.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
class WarrantySource extends NameValue
|
||||
{
|
||||
const CAPI = 'capi';
|
||||
const RAPI = 'rapi';
|
||||
const ADMIN_PANEL = 'admin_panel';
|
||||
const BULK_UPLOAD = 'bulk_upload';
|
||||
const MOBILE = 'mobile';
|
||||
|
||||
const COLLECTION = [
|
||||
'capi' => 'Third Party API',
|
||||
'rapi' => 'Rider API',
|
||||
'admin_panel' => 'Admin Panel',
|
||||
'bulk_upload' => 'Bulk Upload',
|
||||
'mobile' => 'Mobile API',
|
||||
];
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class WarrantyAPILogger
|
|||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function logWarrantyInfo($log_data, $error, $user_id, $action)
|
||||
public function logWarrantyInfo($log_data, $error, $user_id, $action, $source)
|
||||
{
|
||||
$log_entry = new WarrantyAPILog();
|
||||
|
||||
|
|
@ -27,7 +27,8 @@ class WarrantyAPILogger
|
|||
$log_entry->setApiUser($user_id)
|
||||
->setErrors($err_array)
|
||||
->setAllData($json_data)
|
||||
->setAction($action);
|
||||
->setAction($action)
|
||||
->setSource($source);
|
||||
|
||||
$this->em->persist($log_entry);
|
||||
$this->em->flush();
|
||||
|
|
|
|||
Loading…
Reference in a new issue