Add validation service for the insurance data. #727
This commit is contained in:
parent
0675637b52
commit
675bca1592
2 changed files with 239 additions and 0 deletions
|
|
@ -66,6 +66,8 @@ class TestInsuranceConnectorCommand extends Command
|
||||||
->setLine('pcoc')
|
->setLine('pcoc')
|
||||||
->setPublic(false);
|
->setPublic(false);
|
||||||
|
|
||||||
|
// TOOD: add validation here
|
||||||
|
|
||||||
$result = $this->insurance->processApplication($client_data);
|
$result = $this->insurance->processApplication($client_data);
|
||||||
|
|
||||||
error_log(json_encode($result));
|
error_log(json_encode($result));
|
||||||
|
|
|
||||||
237
src/Service/InsuranceClientDataValidator.php
Normal file
237
src/Service/InsuranceClientDataValidator.php
Normal file
|
|
@ -0,0 +1,237 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\MotorVehicleType;
|
||||||
|
|
||||||
|
use App\Insurance\ClientData;
|
||||||
|
use App\Insurance\LineType;
|
||||||
|
use App\Insurance\ClientType;
|
||||||
|
|
||||||
|
class InsuranceClientDataValidator
|
||||||
|
{
|
||||||
|
public function validateClientData(ClientData$client_data)
|
||||||
|
{
|
||||||
|
// client type is required
|
||||||
|
if (empty($client_data->getClientType()))
|
||||||
|
{
|
||||||
|
$error = 'Client type is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// client type values should either be C or I
|
||||||
|
if (($client_data->getClientType() != ClientType::CORPORATE) ||
|
||||||
|
($client_type->ClientType() != ClientType::INDIVIDUAL))
|
||||||
|
{
|
||||||
|
$error = 'Invalid cilent type values. Values should only be C for corporate type or I for individual.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first name is required
|
||||||
|
if (empty($client_data->getFirstName()))
|
||||||
|
{
|
||||||
|
$error = 'First name is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// surname is required
|
||||||
|
if (empty($client_data->getSurname()))
|
||||||
|
{
|
||||||
|
$error = 'Surname is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// corporate name is required
|
||||||
|
if (empty($client_data->getCorporateName()))
|
||||||
|
{
|
||||||
|
$error = 'Corporate name is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// number address is required
|
||||||
|
if (empty($client_data->getAddressNumber()))
|
||||||
|
{
|
||||||
|
$error = 'House number address is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// barangay address is required
|
||||||
|
if (empty($client_data->getAddressBarangay()))
|
||||||
|
{
|
||||||
|
$error = 'Barangay address is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// city address is required
|
||||||
|
if (empty($client_data->getAddressCity()))
|
||||||
|
{
|
||||||
|
$error = 'City address is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// province address is required
|
||||||
|
if (empty($client_data->getAddressProvince()))
|
||||||
|
{
|
||||||
|
$error = 'Province address is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// zipcode is required
|
||||||
|
if (empty($client_data->getZipcode()))
|
||||||
|
{
|
||||||
|
$error = 'Zipcode is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mobile number is required
|
||||||
|
if (empty($client_data->getMobileNumber()))
|
||||||
|
{
|
||||||
|
$error = 'Mobile number is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// email address is required
|
||||||
|
if (empty($client_data->getEmailAddress()))
|
||||||
|
{
|
||||||
|
$error = 'Email address is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make is required
|
||||||
|
if (empty($client_data->getMake()))
|
||||||
|
{
|
||||||
|
$error = 'Vehicle make is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// model is required
|
||||||
|
if (empty($client_data->getMake()))
|
||||||
|
{
|
||||||
|
$error = 'Vehicle make is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// series is required
|
||||||
|
if (empty($client_data->getSeries()))
|
||||||
|
{
|
||||||
|
$error = 'Vehicle series is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// color is required
|
||||||
|
if (empty($client_data->getColor()))
|
||||||
|
{
|
||||||
|
$error = 'Vehicle color is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// plate number is required
|
||||||
|
if (empty($client_data->getPlateNumber()))
|
||||||
|
{
|
||||||
|
$error = 'Plate number is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// plate number is correct format
|
||||||
|
$is_valid_plate = $this->checkPlateNumber($client_data->getPlateNumber());
|
||||||
|
if (!($is_valid_plate))
|
||||||
|
{
|
||||||
|
$error = 'Invalid plate number.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MV file number is required
|
||||||
|
if (empty($client_data->getMvFileNumber()))
|
||||||
|
{
|
||||||
|
$error = 'MV file number is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// motor number is required
|
||||||
|
if (empty($client_data->getMotorNumber()))
|
||||||
|
{
|
||||||
|
$error = 'Motor number is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// serial or chassis number is required
|
||||||
|
if (empty($client_data->getSerialChassis()))
|
||||||
|
{
|
||||||
|
$error = 'Serial or chassis number is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vehicle year model is required
|
||||||
|
if (empty($client_data->getYearModel()))
|
||||||
|
{
|
||||||
|
$error = 'Vehicle year model is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// motor vehicle type id is required
|
||||||
|
if ($client_data->getMvTypeID() == 0)
|
||||||
|
{
|
||||||
|
$error = 'Motor vehicle type must be set.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: should we check if it's a valid MV type?
|
||||||
|
|
||||||
|
// body type is required
|
||||||
|
if ($client_data->getBodyType())
|
||||||
|
{
|
||||||
|
$error = 'Vehicle body type is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// line is required
|
||||||
|
if (empty($client_data->getLine()))
|
||||||
|
{
|
||||||
|
$error = 'Line type is required.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check line if valid
|
||||||
|
if (($client_data->getLine() !== LineType::PRIVATE_CAR) ||
|
||||||
|
($client_data->getLine() !== LineType::PRIVATE_MOTORCYCLE) ||
|
||||||
|
($client_data->getLine() !== LineType::COMMERCIAL_VEHICLE) ||
|
||||||
|
($client_data->getLine() !== LineType::PUBLIC_MOTORCYCLE))
|
||||||
|
{
|
||||||
|
$error = 'Invalid line type.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check line type and flag_public combination
|
||||||
|
// if line type is MCOC, flag_public should be false
|
||||||
|
// if line type is LCOC, flag_public should be true
|
||||||
|
if ($client_data->getLine() == LineType::MCOC)
|
||||||
|
{
|
||||||
|
if ($client_data->isPublic())
|
||||||
|
{
|
||||||
|
$error = 'Line type is invalid for public vehicles.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client_data->getLine() == LineType::LCOC)
|
||||||
|
{
|
||||||
|
if (!($client_data->isPublic()))
|
||||||
|
{
|
||||||
|
$error = 'Line type is invalid for private vehicles.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkPlateNumber($plate)
|
||||||
|
{
|
||||||
|
// check if alphanumeric, max length is 11, no spaces, uppercase
|
||||||
|
$res = preg_match("/^[A-Z0-9]{1,11}+$/", $plate);
|
||||||
|
if ($res)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue