fix: update Task model to reflect some missing fields
This commit is contained in:
parent
54c2c8e897
commit
b48fd48f24
@ -10,6 +10,16 @@ class Task
|
|||||||
|
|
||||||
private int $id;
|
private int $id;
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: This ID is hardcoded for now because we haven't implemented users yet! Specific logic will be required later on.
|
||||||
|
private const task_owner = 1;
|
||||||
|
|
||||||
|
private Carbon $createdAt;
|
||||||
|
|
||||||
|
private Carbon $updatedAt;
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: This is actually the "name" in the db.
|
||||||
private string $title;
|
private string $title;
|
||||||
|
|
||||||
private string $description;
|
private string $description;
|
||||||
@ -27,6 +37,22 @@ class Task
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTaskOwner(): int
|
||||||
|
{
|
||||||
|
return self::task_owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates Task's last updated time.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function touch(): void
|
||||||
|
{
|
||||||
|
$this->updatedAt = Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return $this->title;
|
return $this->title;
|
||||||
@ -94,16 +120,19 @@ class Task
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromArray($taskData): self
|
public static function fromArray($data): self
|
||||||
{
|
{
|
||||||
$task = new self();
|
$task = new self();
|
||||||
|
|
||||||
$task->id = $taskData['id'] ?? null;
|
$task->id = $data['id'] ?? null;
|
||||||
$task->title = $taskData['name'] ?? '';
|
// task owner is discarded from input array
|
||||||
$task->description = $taskData['description'] ?? '';
|
$task->createdAt = Carbon::parse($data['created_at']);
|
||||||
$task->status = $taskData['status'] ?? 'started';
|
$task->updatedAt = Carbon::parse($data['updated_at']);
|
||||||
$task->startDt = $taskData['start'] ?? '';
|
$task->title = $data['name'] ?? '';
|
||||||
$task->endDt = $taskData['end'] ?? '';
|
$task->description = $data['description'] ?? '';
|
||||||
|
$task->startDt = $data['start'] ?? '';
|
||||||
|
$task->endDt = $data['end'] ?? '';
|
||||||
|
$task->status = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED;
|
||||||
|
|
||||||
return $task;
|
return $task;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user