From 5b36e0d8d794ea5977d7baa823ed93aa8befe17a Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Wed, 2 Feb 2022 22:27:58 +0800 Subject: [PATCH] Add QR prefix removal to app api for warranty #644 --- src/Controller/APIController.php | 19 ++++++++++++++++++- .../CAPI/CustomerWarrantyController.php | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9b9e457d..c3a4bbf9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3347,6 +3347,21 @@ class APIController extends Controller implements LoggedController return false; } + // TODO: put this in a service + protected function cleanSerial($serial) + { + // trim and make everything upper case + $clean_serial = trim(strtoupper($serial)); + + + // remove QR prefix if it exists + $prefix = substr($clean_serial, 0, 2); + if ($prefix == 'QR') + $clean_serial = substr($clean_serial, 2); + + return $clean_serial; + } + public function warrantyCheck($serial, EntityManagerInterface $em, Request $req) { // check required parameters and api key @@ -3356,6 +3371,7 @@ class APIController extends Controller implements LoggedController return $res->getReturnResponse(); // check if warranty serial is there + $serial = $this->cleanSerial($serial); $warr_serial = $em->getRepository(WarrantySerial::class)->find($serial); $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]); $batt = null; @@ -3577,7 +3593,8 @@ class APIController extends Controller implements LoggedController $warr_card = $req->files->get('warr_card'); // normalize serial - $serial = trim(strtoupper($serial)); + $serial = $this->cleanSerial($serial); + // $serial = trim(strtoupper($serial)); // process picture uploads $upload_dir = $kernel->getProjectDir() . '/public/warranty_uploads'; diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 89705b14..bd75997b 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -94,6 +94,7 @@ class CustomerWarrantyController extends APIController return preg_replace('/\s+/', '', strtoupper($plate_num)); } + // TODO: put this in a service protected function cleanSerial($serial) { // trim and make everything upper case