From 18c295f2b1fb3e1f15df0b60f6ad127ab953bd26 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 13 Aug 2023 17:36:33 +0800 Subject: [PATCH] Fix customer record association when submitting a delete request #746 --- config/routes/apiv2.yaml | 8 ++++---- src/Controller/CustomerAppAPI/AccountController.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config/routes/apiv2.yaml b/config/routes/apiv2.yaml index 6472fc82..af7d0084 100644 --- a/config/routes/apiv2.yaml +++ b/config/routes/apiv2.yaml @@ -248,16 +248,16 @@ apiv2_rider_review_tags: # account deletion apiv2_account_delete: - path: /apiv2/account + path: /apiv2/account_delete controller: App\Controller\CustomerAppAPI\AccountController::deleteAccount - methods: [DELETE] + methods: [POST] apiv2_account_delete_resend_code: - path: /apiv2/account_resend_code + path: /apiv2/account_delete_resend_code controller: App\Controller\CustomerAppAPI\AccountController:resendCode methods: [POST] apiv2_account_delete_code_validate: - path: /apiv2/account_code_validate + path: /apiv2/account_delete_code_validate controller: App\Controller\CustomerAppAPI\AccountController::validateDeleteCode methods: [POST] \ No newline at end of file diff --git a/src/Controller/CustomerAppAPI/AccountController.php b/src/Controller/CustomerAppAPI/AccountController.php index 135514d3..cf1f6bd2 100644 --- a/src/Controller/CustomerAppAPI/AccountController.php +++ b/src/Controller/CustomerAppAPI/AccountController.php @@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Contracts\Translation\TranslatorInterface; use Catalyst\ApiBundle\Component\Response as ApiResponse; use App\Entity\CustomerDeleteRequest; +use App\Entity\Customer; use App\Service\RisingTideGateway; use DateTime; @@ -81,9 +82,18 @@ class AccountController extends ApiController return new ApiResponse(false, 'Invalid request details provided.'); } + // check if a customer record exists for this phone number + $cust_obj = $this->em->getRepository(Customer::class)->findOneBy([ + 'phone_mobile' => $obj->getPhoneNumber(), + ]); + if (empty($cust_obj)) { + return new ApiResponse(false, 'No account exists for this phone number.'); + } + // confirm the request $obj->setConfirmed(true); $obj->setDateConfirmed(new DateTime()); + $obj->setCustomer($cust_obj); $this->em->flush(); // response