From b3b81e4e27ec63e22ff6ca53335316aa14442073 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Mon, 14 Aug 2023 00:28:27 +0800 Subject: [PATCH] Add transparent check if number is valid before storing new deletion request #746 --- .../CustomerAppAPI/AccountController.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Controller/CustomerAppAPI/AccountController.php b/src/Controller/CustomerAppAPI/AccountController.php index cf1f6bd2..99a77e69 100644 --- a/src/Controller/CustomerAppAPI/AccountController.php +++ b/src/Controller/CustomerAppAPI/AccountController.php @@ -33,8 +33,23 @@ class AccountController extends ApiController // use the test code if we're using a test number or are on test mode $code = $this->getConfirmCode($phone_number); - // build model + $success_msg = 'We have sent a confirmation code to the submitted phone number if it is valid.'; + + // initialize model $obj = new CustomerDeleteRequest(); + + // check if a customer record exists for this phone number + $cust_obj = $this->em->getRepository(Customer::class)->findOneBy([ + 'phone_mobile' => $phone_number, + ]); + if (empty($cust_obj)) { + // return a random id anyway if we don't find this customer + return new ApiResponse(true, $success_msg, [ + 'request_id' => $obj->getID(), + ]); + } + + // phone number is valid, we continue building the model $obj->setPhoneNumber($phone_number); $obj->setReason($reason); $obj->setConfirmCode($code); @@ -50,7 +65,7 @@ class AccountController extends ApiController $this->em->flush(); // response - return new ApiResponse(true, '', [ + return new ApiResponse(true, $success_msg, [ 'request_id' => $obj->getID(), ]); }