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;
|
||||
|
||||
|
||||
// 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 $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
|
||||
{
|
||||
return $this->title;
|
||||
@ -94,16 +120,19 @@ class Task
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function fromArray($taskData): self
|
||||
public static function fromArray($data): self
|
||||
{
|
||||
$task = new self();
|
||||
|
||||
$task->id = $taskData['id'] ?? null;
|
||||
$task->title = $taskData['name'] ?? '';
|
||||
$task->description = $taskData['description'] ?? '';
|
||||
$task->status = $taskData['status'] ?? 'started';
|
||||
$task->startDt = $taskData['start'] ?? '';
|
||||
$task->endDt = $taskData['end'] ?? '';
|
||||
$task->id = $data['id'] ?? null;
|
||||
// task owner is discarded from input array
|
||||
$task->createdAt = Carbon::parse($data['created_at']);
|
||||
$task->updatedAt = Carbon::parse($data['updated_at']);
|
||||
$task->title = $data['name'] ?? '';
|
||||
$task->description = $data['description'] ?? '';
|
||||
$task->startDt = $data['start'] ?? '';
|
||||
$task->endDt = $data['end'] ?? '';
|
||||
$task->status = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED;
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user