Skip to content

Commit b273a50

Browse files
committed
Allow for empty todos.description and todos.category_id
1 parent b839878 commit b273a50

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/Repositories/TodoRepository.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Events\TodoUpdated;
1515
use App\Exceptions\TodoException;
1616
use App\Models\AppLog;
17+
use App\Models\Category;
1718
use App\Models\Todo;
1819
use App\Services\ElasticsearchService;
1920
use App\Traits\RepositoryTraits;
@@ -128,11 +129,17 @@ public function getTodosBySearch($params, $user)
128129
public function createTodo($user, $params)
129130
{
130131
try {
132+
if (empty($category_id)) {
133+
$category_id = Category::where('user_id', $user->id)->value('id');
134+
} else {
135+
$category_id = $params['category_id'];
136+
}
137+
131138
$todo = new Todo;
132139
$todo->uid = Uuid::uuid4()->toString();
133140
$todo->title = $params['title'];
134-
$todo->description = $params['description'];
135-
$todo->category_id = $params['category_id'];
141+
$todo->description = !empty($params['description'])? $params['description'] : '';
142+
$todo->category_id = $category_id;
136143
$todo->user_id = $user->id;
137144
$todo->save();
138145

0 commit comments

Comments
 (0)