Allow for same plate number update on register api call #540

This commit is contained in:
Kendrick Chan 2021-03-19 02:23:22 +08:00
parent b2fcec5462
commit 3bc4bb8db7

View file

@ -88,6 +88,11 @@ class CustomerWarrantyController extends APIController
return trim(strtoupper($serial)); return trim(strtoupper($serial));
} }
protected function cleanPlateNumber($plate_num)
{
return preg_replace('/\s+/', '', strtoupper($plate_num));
}
public function check($serial, EntityManagerInterface $em, Request $req) public function check($serial, EntityManagerInterface $em, Request $req)
{ {
// check required parameters // check required parameters
@ -303,6 +308,8 @@ class CustomerWarrantyController extends APIController
protected function updateWarranty($em, $req, $serial, $inv_filename = null, $wcard_filename = null) protected function updateWarranty($em, $req, $serial, $inv_filename = null, $wcard_filename = null)
{ {
$plate_num = $this->cleanPlateNumber($req->request->get('plate_num'));
error_log('warranty serial check'); error_log('warranty serial check');
// get serial // get serial
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial); $warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
@ -317,7 +324,12 @@ class CustomerWarrantyController extends APIController
// skip warranty if it already exists // skip warranty if it already exists
if ($warr != null) if ($warr != null)
{ {
return new APIResponse(false, 'Warranty registred to a vehicle not in your list of vehicles.'); $warr_plate_num = $this->cleanPlateNumber($warr->getPlateNumber());
if ($plate_num != $warr_plate_num)
{
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
}
/* /*
// check if warranty is registered to a serial owned by customer // check if warranty is registered to a serial owned by customer