Skip to content

Commit

Permalink
Merge pull request #366 from canyongbs/advising-1143
Browse files Browse the repository at this point in the history
[ADVISING-1143]: Add API Capabilities for Care Team
  • Loading branch information
Orrison authored Dec 14, 2023
2 parents 6a38c7b + 482342f commit fc6e8e5
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 3 deletions.
56 changes: 56 additions & 0 deletions app-modules/care-team/graphql/care-team.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
type UserCareTeam @model(class: "AdvisingApp\\CareTeam\\Models\\CareTeam") {
"Unique primary key."
id: ID!
"The user related to this care team assignment."
user: User! @belongsTo
"The educatable in the user's care team."
educatable: Educatable! @morphTo
"The created date of the care team assignment."
created_at: DateTime
"The updated date of the care team assignment."
updated_at: DateTime
}

extend type Query {
"Get a care team assignment by its primary key."
userCareTeam("Search by primary key." id: ID! @whereKey): UserCareTeam
@find
@canResolved(ability: "view")

"Get all care team assignments."
userCareTeams: [UserCareTeam!]! @paginate @canModel(ability: "viewAny")
}

extend type Mutation {
"Create a new care team assignment."
createUserCareTeam(
"The user to add to the care team of."
user_id: ID!
@rules(
apply: [
"required"
"exists:users,id"
"AdvisingApp\\CareTeam\\Rules\\UniqueCareTeamRule"
]
)

"The educatable to add to the care team."
educatable_id: ID!
@rules(
apply: [
"required"
"AdvisingApp\\CareTeam\\Rules\\EducatableIdExistsRule"
]
)

"The type of educatable to add to the care team."
educatable_type: String!
@rules(apply: ["required", "in:student,prospect"])
): UserCareTeam! @create @canModel(ability: "create")

"Delete an existing care team assignment."
deleteUserCareTeam(
"The primary key of the care team assignment."
id: ID! @whereKey
): UserCareTeam @delete @canFind(ability: "delete", find: "id")
}
2 changes: 1 addition & 1 deletion app-modules/care-team/src/Models/CareTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function educatable(): MorphTo

public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTimestamps();
return $this->belongsTo(User::class);
}

public static function executeFromCampaignAction(CampaignAction $action): bool|string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace AdvisingApp\CareTeam\Providers;

use Filament\Panel;
use App\Concerns\GraphSchemaDiscovery;
use Illuminate\Support\ServiceProvider;
use AdvisingApp\CareTeam\CareTeamPlugin;
use AdvisingApp\CareTeam\Models\CareTeam;
Expand All @@ -46,6 +47,8 @@

class CareTeamServiceProvider extends ServiceProvider
{
use GraphSchemaDiscovery;

public function register(): void
{
Panel::configureUsing(fn (Panel $panel) => $panel->plugin(new CareTeamPlugin()));
Expand All @@ -58,6 +61,8 @@ public function boot(): void
]);

$this->registerRolesAndPermissions();

$this->discoverSchema(__DIR__ . '/../../graphql/care-team.graphql');
}

protected function registerRolesAndPermissions(): void
Expand Down
65 changes: 65 additions & 0 deletions app-modules/care-team/src/Rules/EducatableIdExistsRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
<COPYRIGHT>
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved.
Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.
Notice:
- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.
For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at [email protected].
</COPYRIGHT>
*/

namespace AdvisingApp\CareTeam\Rules;

use Closure;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Relations\Relation;

class EducatableIdExistsRule implements DataAwareRule, ValidationRule
{
protected $data = [];

public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (
! Relation::getMorphedModel($this->data['educatable_type'])::query()
->whereKey($value)
->exists()
) {
$fail('The educatable does not exist.');
}
}

public function setData(array $data): static
{
$this->data = $data;

return $this;
}
}
67 changes: 67 additions & 0 deletions app-modules/care-team/src/Rules/UniqueCareTeamRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
<COPYRIGHT>
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved.
Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.
Notice:
- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.
For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at [email protected].
</COPYRIGHT>
*/

namespace AdvisingApp\CareTeam\Rules;

use Closure;
use AdvisingApp\CareTeam\Models\CareTeam;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;

class UniqueCareTeamRule implements DataAwareRule, ValidationRule
{
protected $data = [];

public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (
CareTeam::query()
->where('educatable_id', $this->data['educatable_id'])
->where('educatable_type', $this->data['educatable_type'])
->where('user_id', $value)
->exists()
) {
$fail('The user is already on the care team.');
}
}

public function setData(array $data): static
{
$this->data = $data;

return $this;
}
}
17 changes: 15 additions & 2 deletions app-modules/notifications/graphql/subscription.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ extend type Mutation {
"Create a new subscription."
createUserSubscription(
"The user to subscribe."
user_id: ID! @rules(apply: ["required", "exists:users,id"])
user_id: ID!
@rules(
apply: [
"required"
"exists:users,id"
"AdvisingApp\\Notifications\\Rules\\UniqueSubscriptionRule"
]
)

"The subscribable to subscribe to."
subscribable_id: ID! @rules(apply: ["required"])
subscribable_id: ID!
@rules(
apply: [
"required"
"AdvisingApp\\Notifications\\Rules\\SubscribableIdExistsRule"
]
)

"The type of subscribable to subscribe to."
subscribable_type: String!
Expand Down
65 changes: 65 additions & 0 deletions app-modules/notifications/src/Rules/SubscribableIdExistsRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
<COPYRIGHT>
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved.
Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.
Notice:
- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.
For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at [email protected].
</COPYRIGHT>
*/

namespace AdvisingApp\Notifications\Rules;

use Closure;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Relations\Relation;

class SubscribableIdExistsRule implements DataAwareRule, ValidationRule
{
protected $data = [];

public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (
! Relation::getMorphedModel($this->data['subscribable_type'])::query()
->whereKey($value)
->exists()
) {
$fail('The subscribable does not exist.');
}
}

public function setData(array $data): static
{
$this->data = $data;

return $this;
}
}
67 changes: 67 additions & 0 deletions app-modules/notifications/src/Rules/UniqueSubscriptionRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
<COPYRIGHT>
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved.
Advising App™ is licensed under the Elastic License 2.0. For more details,
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE.
Notice:
- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Advising App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.
For more information or inquiries please visit our website at
https://www.canyongbs.com or contact us via email at [email protected].
</COPYRIGHT>
*/

namespace AdvisingApp\Notifications\Rules;

use Closure;
use AdvisingApp\Notifications\Models\Subscription;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;

class UniqueSubscriptionRule implements DataAwareRule, ValidationRule
{
protected $data = [];

public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (
Subscription::query()
->where('subscribable_id', $this->data['subscribable_id'])
->where('subscribable_type', $this->data['subscribable_type'])
->where('user_id', $value)
->exists()
) {
$fail('The user is already subscribed.');
}
}

public function setData(array $data): static
{
$this->data = $data;

return $this;
}
}

0 comments on commit fc6e8e5

Please sign in to comment.