NEW: endpoints DELETE event atteendee by ID or REF (#33986)

* pricate function _fetch that fetches the attendee data based on either (row)id or referece

* NEW: endpoints DELETE event atteendee by ID or REF

* fix missing }

---------

Co-authored-by: Jon Bendtsen <xcodeauthor@jonb.dk>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Jon Bendtsen 2025-05-06 12:28:48 +02:00 committed by GitHub
parent 7bb258b5ee
commit 474cb2e54e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,6 +68,82 @@ class EventAttendees extends DolibarrApi
$this->event_attendees = new ConferenceOrBoothAttendee($this->db);
}
/**
* Delete an event attendee
*
* @param int $id event attendee ID
* @return array
* @phan-return array<array<string,int|string>>
* @phpstan-return array<array<string,int|string>>
*
* @url DELETE {id}
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500
*/
public function deleteById($id)
{
$allowaccess = $this->_checkAccessRights('delete', 0);
if (!$allowaccess) {
throw new RestException(403, 'denied read access to Event attendees');
}
$result = $this->event_attendees->fetch($id, '');
if (!$result) {
throw new RestException(404, 'Event attendee with id '.$id.' not found');
}
if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete event attendee : '.$this->event_attendees->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'event attendee deleted'
)
);
}
/**
* Delete an event attendee
*
* @param string $ref event attendee ref
* @return array
* @phan-return array<array<string,int|string>>
* @phpstan-return array<array<string,int|string>>
*
* @url DELETE ref/{ref}
*
* @throws RestException 403
* @throws RestException 404
* @throws RestException 500
*/
public function deleteByRef($ref)
{
$allowaccess = $this->_checkAccessRights('delete', 0);
if (!$allowaccess) {
throw new RestException(403, 'denied read access to Event attendees');
}
$result = $this->event_attendees->fetch(0, $ref);
if (!$result) {
throw new RestException(404, "Event attendee with ref ".$ref." not found");
}
if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete event attendee : '.$this->event_attendees->error);
}
return array(
'success' => array(
'code' => 200,
'message' => 'event attendee deleted'
)
);
}
/**
* Get properties of a event attendee by id
*