From ee40aeecce8d82e8aa341cd1dd5e1e9f3fa8dac4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Oct 2020 12:21:54 +0200 Subject: [PATCH] Standardize API --- .../comm/propal/class/api_proposals.class.php | 23 ++++++++++++------- .../facture/class/api_invoices.class.php | 8 +++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 0f157396f35..90e60bf6adb 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -507,9 +507,10 @@ class Proposals extends DolibarrApi * Delete a contact type of given commercial proposal * * @param int $id Id of commercial proposal to update - * @param int $rowid Row key of the contact in the array contact_ids. + * @param int $contactid Row key of the contact in the array contact_ids. + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid} + * @url DELETE {id}/contact/{contactid}/{type} * * @return int * @@ -517,7 +518,7 @@ class Proposals extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid) + public function deleteContact($id, $contactid, $type) { if (!DolibarrApiAccess::$user->rights->propal->creer) { throw new RestException(401); @@ -533,13 +534,19 @@ class Proposals extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->propal->delete_contact($rowid); + $contacts = $this->invoice->liste_contact(); - if (!$result) { - throw new RestException(500, 'Error when deleted the contact'); - } + foreach ($contacts as $contact) { + if ($contact['id'] == $contactid && $contact['code'] == $type) { + $result = $this->propal->delete_contact($contact['rowid']); - return $this->propal; + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + } + } + + return $this->_cleanObjectDatas($this->propal); } /** diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 1c423a2e459..643fb7eddd0 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -476,10 +476,10 @@ class Invoices extends DolibarrApi * Delete a contact type of given invoice * * @param int $id Id of invoice to update - * @param int $rowid Row key of the contact in the array contact_ids. + * @param int $contactid Row key of the contact in the array contact_ids. * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid}/{type} + * @url DELETE {id}/contact/{contactid}/{type} * * @return array * @@ -487,7 +487,7 @@ class Invoices extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid, $type) + public function deleteContact($id, $contactid, $type) { if (!DolibarrApiAccess::$user->rights->facture->creer) { throw new RestException(401); @@ -506,7 +506,7 @@ class Invoices extends DolibarrApi $contacts = $this->invoice->liste_contact(); foreach ($contacts as $contact) { - if ($contact['id'] == $rowid && $contact['code'] == $type) { + if ($contact['id'] == $contactid && $contact['code'] == $type) { $result = $this->invoice->delete_contact($contact['rowid']); if (!$result) {