diff --git a/backend/app/Http/Controllers/Api/ChildrenController.php b/backend/app/Http/Controllers/Api/ChildrenController.php index 06cbf928..0809961d 100644 --- a/backend/app/Http/Controllers/Api/ChildrenController.php +++ b/backend/app/Http/Controllers/Api/ChildrenController.php @@ -274,7 +274,7 @@ class ChildrenController extends Controller { return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']]; } - if (null === ($result = Child::where('first_name', 'LIKE', '%'.$r->keyword.'%')->orWhere('last_name', 'LIKE', '%'.$r->keyword.'%')->orderBy('created_at', 'desc')->get())) { + if (null === ($result = Child::where('first_name', 'LIKE', '%'.$r->keyword.'%')->orWhere('last_name', 'LIKE', '%'.$r->keyword.'%')->orderBy('updated_at', 'desc')->get())) { // 親一覧の取得に失敗 return ['status_code' => 400]; } @@ -286,7 +286,7 @@ class ChildrenController extends Controller { public function list () { $child_select = ['id', 'first_name', 'last_name', 'tel', 'image']; - if (null === ($result = Child::select($child_select)->orderBy('created_at', 'desc')->get())) { + if (null === ($result = Child::select($child_select)->orderBy('updated_at', 'desc')->get())) { // 親一覧の取得に失敗 return ['status_code' => 400]; } @@ -302,7 +302,7 @@ class ChildrenController extends Controller { $result = []; $child_select = ['id', 'image', 'first_name', 'last_name', 'company', 'tel', 'email']; - if (null === ($list = FatherRelation::select('child_id')->where('father_id', (int)$r->father_id)->orderBy('created_at', 'desc')->get())) { + if (null === ($list = FatherRelation::select('child_id')->where('father_id', (int)$r->father_id)->orderBy('updated_at', 'desc')->get())) { return ['status_code' => 400]; } @@ -319,7 +319,7 @@ class ChildrenController extends Controller { $result = []; $child_select = ['id', 'image', 'last_name', 'first_name']; - if (null === ($list = MeetingApprovals::select('child_id')->where('meeting_id', (int)$r->meeting_id)->orderBy('created_at', 'desc')->get())) { + if (null === ($list = MeetingApprovals::select('child_id')->where('meeting_id', (int)$r->meeting_id)->orderBy('updated_at', 'desc')->get())) { return ['status_code' => 400]; } @@ -341,7 +341,7 @@ class ChildrenController extends Controller { $child_select = ['id', 'image', 'last_name', 'first_name', 'tel']; $meeting_approvals_select = ['approval_at']; - if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$r->meeting_id)->whereNull('approval_at')->orderBy('created_at', 'desc')->get())) { + if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$r->meeting_id)->whereNull('approval_at')->orderBy('updated_at', 'desc')->get())) { return ['status_code' => 400]; } @@ -364,7 +364,7 @@ class ChildrenController extends Controller { $child_select = ['id', 'image', 'last_name', 'first_name', 'tel']; $meeting_approvals_select = ['approval_at']; - if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', $r->meeting_id)->whereNotNull('approval_at')->orderBy('created_at', 'desc')->get())) { + if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', $r->meeting_id)->whereNotNull('approval_at')->orderBy('updated_at', 'desc')->get())) { return ['status_code' => 400]; } diff --git a/backend/app/Http/Controllers/Api/FatherRelationsController.php b/backend/app/Http/Controllers/Api/FatherRelationsController.php index af0e2399..e40da154 100644 --- a/backend/app/Http/Controllers/Api/FatherRelationsController.php +++ b/backend/app/Http/Controllers/Api/FatherRelationsController.php @@ -15,17 +15,18 @@ use App\Models\Meeting; use App\Models\MeetingApprovals; class FatherRelationsController extends Controller { - public function check (Request $r) { - - $father_id = (int)$r->father_id; - - if (FatherRelation::select('id')->where('father_id', $father_id)->count() == 0) { + public function checkNull () { + if (FatherRelation::select('id')->where('father_id', (int)session()->get('fathers')['id'])->count() == 0) { return ['status_code' => 401, 'error_messages' => ['契約上限数に達した為、メンバー追加できません。']]; } - $father = Father::select('relation_limit')->where('id', $father_id)->first(); + return ['status_code' => 200]; + } - if ($father->relation_limit <= FatherRelation::select('id')->where('father_id', $father_id)->count()) { + public function check () { + $father = Father::select('relation_limit')->where('id', (int)session()->get('fathers')['id'])->first(); + + if ($father->relation_limit <= FatherRelation::select('id')->where('father_id', (int)session()->get('fathers')['id'])->count()) { return ['status_code' => 401, 'error_messages' => ['契約上限数に達した為、メンバー追加できません。']]; } diff --git a/backend/app/Http/Controllers/Api/MeetingsController.php b/backend/app/Http/Controllers/Api/MeetingsController.php index 81b0b120..754ba081 100644 --- a/backend/app/Http/Controllers/Api/MeetingsController.php +++ b/backend/app/Http/Controllers/Api/MeetingsController.php @@ -447,7 +447,7 @@ class MeetingsController extends Controller { $child_select = ['image']; // 取得に成功 - if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)session()->get('fathers')['id'])->where('is_favorite', 0)->orderBy('created_at', 'desc')->get())) { + if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)session()->get('fathers')['id'])->where('is_favorite', 0)->orderBy('updated_at', 'desc')->get())) { return ['status_code' => 400]; } diff --git a/backend/app/Models/TelActivation.php b/backend/app/Models/TelActivation.php index 24b517dd..3902d68e 100644 --- a/backend/app/Models/TelActivation.php +++ b/backend/app/Models/TelActivation.php @@ -8,5 +8,5 @@ use Illuminate\Database\Eloquent\Model; class TelActivation extends Model { use HasFactory; - protected $fillable = ['type', 'child_id', 'father_id', 'tel', 'token', 'ttl']; + protected $fillable = ['type', 'child_id', 'tel', 'token', 'ttl']; } diff --git a/backend/database/migrations/2021_08_13_050204_create_tel_activations_table.php b/backend/database/migrations/2021_08_13_050204_create_tel_activations_table.php index 2c7fa5ca..6428ca31 100644 --- a/backend/database/migrations/2021_08_13_050204_create_tel_activations_table.php +++ b/backend/database/migrations/2021_08_13_050204_create_tel_activations_table.php @@ -18,8 +18,6 @@ class CreateTelActivationsTable extends Migration $table->unsignedTinyInteger('type'); $table->unsignedBigInteger('child_id')->nullable(); $table->foreign('child_id')->references('id')->on('children')->onDelete('cascade'); - $table->unsignedBigInteger('father_id')->nullable(); - $table->foreign('father_id')->references('id')->on('fathers')->onDelete('cascade'); $table->string('tel', 11)->unique(); $table->string('token', 100)->unique(); $table->dateTime('ttl'); diff --git a/backend/routes/api.php b/backend/routes/api.php index d0dd39f7..5bf34612 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -143,6 +143,7 @@ Route::group(['prefix' => 'fathers'], function () { // FatherRelationsController Route::group(['prefix' => 'relations'], function () { + Route::get('/checkNull', '\App\Http\Controllers\Api\FatherRelationsController@checkNull'); Route::get('/check', '\App\Http\Controllers\Api\FatherRelationsController@check'); Route::post('/register', '\App\Http\Controllers\Api\FatherRelationsController@register'); Route::put('/updateHireDate/{child_id}', '\App\Http\Controllers\Api\FatherRelationsController@updateHireDate');