api(task): ensure sequence_id always starts at 1

This commit is contained in:
Matthew Penner 2023-01-24 16:18:38 -07:00
parent 2b14e46eec
commit 866b6df4b0
No known key found for this signature in database

View file

@ -56,6 +56,11 @@ class ScheduleTaskController extends ClientApiController
$sequenceId = ($lastTask->sequence_id ?? 0) + 1;
$requestSequenceId = $request->integer('sequence_id', $sequenceId);
// Ensure that the sequence id is at least 1.
if ($requestSequenceId < 1) {
$requestSequenceId = 1;
}
// If the sequence id from the request is greater than or equal to the next available
// sequence id, we don't need to do anything special. Otherwise, we need to update
// the sequence id of all tasks that are greater than or equal to the request sequence
@ -105,6 +110,10 @@ class ScheduleTaskController extends ClientApiController
$this->connection->transaction(function () use ($request, $schedule, $task) {
$sequenceId = $request->integer('sequence_id', $task->sequence_id);
// Ensure that the sequence id is at least 1.
if ($sequenceId < 1) {
$sequenceId = 1;
}
// Shift all other tasks in the schedule up or down to make room for the new task.
if ($sequenceId < $task->sequence_id) {