From 8c7f4ab09f1a190986364e57dbc73558a3ee4efc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 Jan 2020 20:22:10 +1100 Subject: [PATCH] Projects and Tasks factories. (#3234) * Working on projects and tasks * Fixes for company transformer * projects and tasks factories --- app/Console/Commands/CreateTestData.php | 27 ++++++++++++++++++++++++- app/Models/Task.php | 2 ++ app/Transformers/TaskTransformer.php | 2 +- database/factories/ProjectFactory.php | 12 +++++++++++ database/factories/TaskFactory.php | 11 ++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 database/factories/ProjectFactory.php create mode 100644 database/factories/TaskFactory.php diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 2855457d02..11e1bfef63 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -145,6 +145,13 @@ class CreateTestData extends Command $this->info('creating vendor for client #'.$client->id); $this->createVendor($client); + $this->info('creating task for client #'.$client->id); + $this->createTask($client); + + $this->info('creating project for client #'.$client->id); + $this->createProject($client); + + } } @@ -221,6 +228,11 @@ class CreateTestData extends Command $this->info('creating vendor for client #'.$client->id); $this->createVendor($client); + $this->info('creating task for client #'.$client->id); + $this->createTask($client); + + $this->info('creating project for client #'.$client->id); + $this->createProject($client); } } @@ -297,6 +309,11 @@ class CreateTestData extends Command $this->info('creating vendor for client #'.$client->id); $this->createVendor($client); + $this->info('creating task for client #'.$client->id); + $this->createTask($client); + + $this->info('creating project for client #'.$client->id); + $this->createProject($client); } } @@ -364,11 +381,19 @@ class CreateTestData extends Command private function createTask($client) { + $vendor = factory(\App\Models\Task::class)->create([ + 'user_id' => $client->user->id, + 'company_id' => $client->company->id + ]); } private function createProject($client) { - + + $vendor = factory(\App\Models\Project::class)->create([ + 'user_id' => $client->user->id, + 'company_id' => $client->company->id + ]); } private function createInvoice($client) diff --git a/app/Models/Task.php b/app/Models/Task.php index 0a4e5d53d7..bea4fe51ca 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -13,10 +13,12 @@ namespace App\Models; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; class Task extends BaseModel { use MakesHash; + use SoftDeletes; protected $fillable = [ 'client_id', diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php index 6b9352b453..7ccb2c8a68 100644 --- a/app/Transformers/TaskTransformer.php +++ b/app/Transformers/TaskTransformer.php @@ -35,7 +35,7 @@ class TaskTransformer extends EntityTransformer return [ 'id' => (string) $this->encodePrimaryKey($task->id), 'description' => $task->description ?: '', - 'duration' => $task->getDuration() ?: 0, + // 'duration' => $task->getDuration() ?: 0, 'updated_at' => (int)$task->updated_at, 'archived_at' => (int)$task->deleted_at, 'invoice_id' => $this->encodePrimaryKey($task->invoice_id), diff --git a/database/factories/ProjectFactory.php b/database/factories/ProjectFactory.php new file mode 100644 index 0000000000..859745cb7b --- /dev/null +++ b/database/factories/ProjectFactory.php @@ -0,0 +1,12 @@ +define(App\Models\Project::class, function (Faker $faker) { + return [ + 'name' => $faker->name(), + 'description' => $faker->text(50), + ]; +}); diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php new file mode 100644 index 0000000000..d01f8781d6 --- /dev/null +++ b/database/factories/TaskFactory.php @@ -0,0 +1,11 @@ +define(App\Models\Task::class, function (Faker $faker) { + return [ + 'description' => $faker->text(50), + ]; +});