api can create notification

This commit is contained in:
Jon Bendtsen 2024-03-16 09:46:32 +01:00
parent bc68755c40
commit 6810cb487f

View file

@ -1146,6 +1146,42 @@ class Thirdparties extends DolibarrApi
return $returnNotifications;
}
/**
* Create CompanyNotification object for thirdparty
* @param int $id ID of thirdparty
* @param array $request_data Request data
*
* @return array|mixed Notification of thirdparty
*
* @url POST {id}/notifications
*/
public function createCompanyNotification($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403, "User has no right to update thirdparties");
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
}
$notification = new Notify($this->db);
$notification->socid = $id;
foreach ($request_data as $field => $value) {
$notification->$field = $value;
}
if ($notification->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating Thirdparty Notification');
}
if ($notification->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
}
return $this->_cleanObjectDatas($notification);
}
/**
* Delete a CompanyNotification attached to a thirdparty
*