Add transparent check if number is valid before storing new deletion request #746

This commit is contained in:
Ramon Gutierrez 2023-08-14 00:28:27 +08:00
parent 18c295f2b1
commit b3b81e4e27

View file

@ -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(),
]);
}