diff --git a/app/config/errors.php b/app/config/errors.php index bc2c436313..e5c2d4e5bd 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -4,6 +4,7 @@ * List of server wide error codes and their respective messages. */ +use Appwrite\Enum\MessageStatus; use Appwrite\Extend\Exception; return [ @@ -871,10 +872,14 @@ return [ 'description' => 'Message with the target ID is not a push target.', 'code' => 400, ], + Exception::MESSAGE_MISSING_SCHEDULE => [ + 'name' => Exception::MESSAGE_MISSING_SCHEDULE, + 'description' => 'Message can not have status ' . MessageStatus::SCHEDULED . ' without a schedule.', + 'code' => 400, + ], Exception::SCHEDULE_NOT_FOUND => [ 'name' => Exception::SCHEDULE_NOT_FOUND, 'description' => 'Schedule with the requested ID could not be found.', 'code' => 404, ], - ]; diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 7e27cf15a4..de20c053e0 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2287,6 +2287,10 @@ App::post('/v1/messaging/messages/email') throw new Exception(Exception::MESSAGE_MISSING_TARGET); } + if ($status === MessageStatus::SCHEDULED && \is_null($scheduledAt)) { + throw new Exception(Exception::MESSAGE_MISSING_SCHEDULE); + } + $mergedTargets = \array_merge($targets, $cc, $bcc); if (!empty($mergedTargets)) { @@ -2401,6 +2405,10 @@ App::post('/v1/messaging/messages/sms') throw new Exception(Exception::MESSAGE_MISSING_TARGET); } + if ($status === MessageStatus::SCHEDULED && \is_null($scheduledAt)) { + throw new Exception(Exception::MESSAGE_MISSING_SCHEDULE); + } + if (!empty($targets)) { $foundTargets = $dbForProject->find('targets', [ Query::equal('$id', $targets), @@ -2516,6 +2524,10 @@ App::post('/v1/messaging/messages/push') throw new Exception(Exception::MESSAGE_MISSING_TARGET); } + if ($status === MessageStatus::SCHEDULED && \is_null($scheduledAt)) { + throw new Exception(Exception::MESSAGE_MISSING_SCHEDULE); + } + if (!empty($targets)) { $foundTargets = $dbForProject->find('targets', [ Query::equal('$id', $targets), diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index b1d654c400..183f4a812a 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -262,6 +262,7 @@ class Exception extends \Exception public const MESSAGE_TARGET_NOT_EMAIL = 'message_target_not_email'; public const MESSAGE_TARGET_NOT_SMS = 'message_target_not_sms'; public const MESSAGE_TARGET_NOT_PUSH = 'message_target_not_push'; + public const MESSAGE_MISSING_SCHEDULE = 'message_missing_schedule'; /** Schedules */ public const SCHEDULE_NOT_FOUND = 'schedule_not_found';