diff --git a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamMerchantTeamsController.php b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamMerchantTeamsController.php index 65300cc..6d2e607 100644 --- a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamMerchantTeamsController.php +++ b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamMerchantTeamsController.php @@ -82,19 +82,27 @@ public function store(): JsonResponse try { - $model = new TeamMerchantTeam(); - - foreach ($validationArray as $key => $validationRule) { - $value = $this->request->get($key); - if ((isset($value))) { - $model->$key = $value; + $model = TeamMerchantTeam::where('team_id', $this->request->get('team_id')) + ->where('merchant_team_id', $this->request->get('merchant_team_id')) + ->first(); + + if (!$model) { + $model = new TeamMerchantTeam(); + + foreach ($validationArray as $key => $validationRule) { + $value = $this->request->get($key); + if ((isset($value))) { + $model->$key = $value; + } } - } - $model->save(); + $model->save(); + + } $this->message = ApiResponse::RESPONSE_SAVED->value; - $this->data = $model; + + $this->data = $model; } catch (Exception $e) { diff --git a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamServiceTeamsController.php b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamServiceTeamsController.php index 8f1538e..b71af2c 100644 --- a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamServiceTeamsController.php +++ b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamServiceTeamsController.php @@ -82,19 +82,27 @@ public function store(): JsonResponse try { - $model = new TeamServiceTeam(); - - foreach ($validationArray as $key => $validationRule) { - $value = $this->request->get($key); - if ((isset($value))) { - $model->$key = $value; + $model = TeamServiceTeam::where('team_id', $this->request->get('team_id')) + ->where('service_team_id', $this->request->get('service_team_id')) + ->first(); + + if (!$model) { + $model = new TeamServiceTeam(); + + foreach ($validationArray as $key => $validationRule) { + $value = $this->request->get($key); + if ((isset($value))) { + $model->$key = $value; + } } - } - $model->save(); + $model->save(); + + } $this->message = ApiResponse::RESPONSE_SAVED->value; - $this->data = $model; + + $this->data = $model; } catch (Exception $e) { diff --git a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamsController.php b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamsController.php index cc20595..caed790 100644 --- a/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamsController.php +++ b/app/Http/Controllers/Api/V1/Admin/ApiAdminTeamsController.php @@ -20,11 +20,15 @@ class ApiAdminTeamsController extends Controller /** * Set the related data the GET request is allowed to ask for */ - public array $availableRelations = []; + public array $availableRelations = [ + 'teamsThisTeamIsMerchantFor', + 'teamsThisTeamIsServiceFor', + ]; public static array $searchableFields = [ 'id', 'name', + ]; /** diff --git a/app/Models/Team.php b/app/Models/Team.php index 3a4d4e4..8078816 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -22,4 +22,24 @@ public function auditItems(): MorphMany { return $this->morphMany(AuditItem::class, 'auditable'); } + + public function teamMerchantTeams(): HasMany + { + return $this->hasMany(TeamMerchantTeam::class, 'team_id', 'id'); + } + + public function teamsThisTeamIsMerchantFor(): HasMany + { + return $this->hasMany(TeamMerchantTeam::class, 'merchant_team_id', 'id'); + } + + public function teamServiceTeams(): HasMany + { + return $this->hasMany(TeamServiceTeam::class, 'team_id', 'id'); + } + + public function teamsThisTeamIsServiceFor(): HasMany + { + return $this->hasMany(TeamServiceTeam::class, 'service_team_id', 'id'); + } } diff --git a/resources/js/Components/Admin/AdminTeamSelectComponent.vue b/resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamSelectComponent.vue similarity index 67% rename from resources/js/Components/Admin/AdminTeamSelectComponent.vue rename to resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamSelectComponent.vue index 53ead9f..1c6db2d 100644 --- a/resources/js/Components/Admin/AdminTeamSelectComponent.vue +++ b/resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamSelectComponent.vue @@ -1,15 +1,12 @@ diff --git a/resources/js/Components/Admin/AdminTeamMerchantTeamsComponent.vue b/resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamsComponent.vue similarity index 61% rename from resources/js/Components/Admin/AdminTeamMerchantTeamsComponent.vue rename to resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamsComponent.vue index cd39dfb..8c220a5 100644 --- a/resources/js/Components/Admin/AdminTeamMerchantTeamsComponent.vue +++ b/resources/js/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamsComponent.vue @@ -1,9 +1,12 @@ + + diff --git a/resources/js/Components/Admin/AdminTeamServiceTeamsComponent.vue b/resources/js/Components/Admin/TeamServiceTeams/AdminTeamServiceTeamsComponent.vue similarity index 62% rename from resources/js/Components/Admin/AdminTeamServiceTeamsComponent.vue rename to resources/js/Components/Admin/TeamServiceTeams/AdminTeamServiceTeamsComponent.vue index 5efdaec..0600973 100644 --- a/resources/js/Components/Admin/AdminTeamServiceTeamsComponent.vue +++ b/resources/js/Components/Admin/TeamServiceTeams/AdminTeamServiceTeamsComponent.vue @@ -1,9 +1,12 @@