Browse Source

Make test passed for family_member_connections entries

family_member_connections
Nafies Luthfi 5 years ago
parent
commit
23c82bfbf5
  1. 17
      app/Http/Controllers/FamilyActionsController.php
  2. 27
      app/User.php
  3. 35
      database/migrations/2021_03_28_091809_create_family_member_connections_table.php
  4. 4
      tests/Feature/ManageUserFamiliesTest.php

17
app/Http/Controllers/FamilyActionsController.php

@ -2,10 +2,11 @@
namespace App\Http\Controllers;
use App\User;
use App\Couple;
use Ramsey\Uuid\Uuid;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;
class FamilyActionsController extends Controller
{
@ -26,6 +27,12 @@ class FamilyActionsController extends Controller
if ($request->get('set_father_id')) {
$user->father_id = $request->get('set_father_id');
$user->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $request->get('set_father_id'),
]);
} else {
$father = new User;
$father->id = Uuid::uuid4()->toString();
@ -57,6 +64,12 @@ class FamilyActionsController extends Controller
if ($request->get('set_mother_id')) {
$user->mother_id = $request->get('set_mother_id');
$user->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $request->get('set_mother_id'),
]);
} else {
$mother = new User;
$mother->id = Uuid::uuid4()->toString();

27
app/User.php

@ -5,6 +5,7 @@ namespace App;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;
class User extends Authenticatable
@ -76,6 +77,12 @@ class User extends Authenticatable
$this->father_id = $father->id;
$this->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $father->id,
]);
return $father;
}
@ -93,6 +100,12 @@ class User extends Authenticatable
$this->mother_id = $mother->id;
$this->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $mother->id,
]);
return $mother;
}
@ -147,6 +160,13 @@ class User extends Authenticatable
'marriage_date' => $marriageDate,
'manager_id' => auth()->id(),
]);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $wife->id,
]);
return $wife;
}
@ -166,6 +186,13 @@ class User extends Authenticatable
'marriage_date' => $marriageDate,
'manager_id' => auth()->id(),
]);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $husband->id,
]);
return $husband;
}

35
database/migrations/2021_03_28_091809_create_family_member_connections_table.php

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFamilyMemberConnectionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('family_member_connections', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('requester_id');
$table->uuid('requested_id');
$table->timestamps();
$table->unique(['requester_id', 'requested_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('family_member_connections');
}
}

4
tests/Feature/ManageUserFamiliesTest.php

@ -93,8 +93,8 @@ class ManageUserFamiliesTest extends TestCase
$child = User::where('name', 'Nama Anak 1')->first();
$this->seeInDatabase('family_member_connections', [
'requester_id' => $user->id,
'requested_id' => $child->id,
'requester_id' => $child->id,
'requested_id' => $user->id,
]);
}

Loading…
Cancel
Save