try { if (!has_access($request)) { return access_denied($response); } $requestData = $request->getBody()->getContents(); $data = json_decode($requestData, true); $contact = contactParser($data); if ($contact->getId() == null || $contact->getId() == -1) { return error($response, 'DELETE A CONTACT WITH NO ID IS NOT POSSIBLE'); } if ($contact->getExchangeId() == null || $contact->getExchangeId() == -1 || $contact->getExchangeId() == "") { return error($response, 'DELETE A CONTACT WITH NO EXCHANGE ID IS NOT POSSIBLE'); } $contactService = new ContactService(); $exchangeService = new ExchangeService(); if (!$contactService->deleteContact($contact)) { return error($response, 'ERROR DURING DELETING FROM DATABASE'); } if (!$exchangeService->deleteContact($contact)) { return error($response, 'ERROR DURING DELETING FROM EXCHANGE'); } return $response->write(json_encode('Delete with success', true)); } catch (Exception $e) { error_log($e->getMessage()); } return error($response, ' DELETE CONTACT UNKNOWN ERROR'); }); $app->post('/searchContacts', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) use($app) { try { if (!has_access($request)) { return access_denied($response);
/** * Sets an individual contact to 'REMOVED' status * @param string $accessToken - Valid access token * @param mixed $contact - Either a Contact id or the Contact itself * @throws IllegalArgumentException - if an int or Contact object is not provided * @return boolean */ public function deleteContact($accessToken, $contact) { $contactId = $this->getArgumentId($contact, 'Contact'); return $this->contactService->deleteContact($accessToken, $contactId); }