From 2253be2c44bd0e07111bae6cece2f74d52016055 Mon Sep 17 00:00:00 2001 From: Nuno Pereira Date: Wed, 14 Aug 2024 16:27:23 +0100 Subject: [PATCH] Added HasReferralLink trait --- app/Actions/Fortify/CreateNewUser.php | 5 +++- app/Console/Commands/CreateDbSchema.php | 4 +-- app/Maintenance/EnvMaintenanceMode.php | 25 ++++++++----------- app/Models/Participant.php | 2 ++ app/Models/StudentAssociation.php | 2 ++ .../StudentAssociationParticipation.php | 2 ++ app/Traits/HasReferralLink.php | 11 ++++++++ tests/Feature/ReferalTest.php | 13 ++++------ 8 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 app/Traits/HasReferralLink.php diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 94e280d8..291a8955 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -44,6 +44,7 @@ public function create(array $input): User } */ + /* $student_association = StudentAssociation::firstWhere('code', $promoter); if (!is_null($student_association)) { $student_association->points = $student_association->points + 20; @@ -56,6 +57,7 @@ public function create(array $input): User $student_association->save(); } } + */ } $data = [ @@ -67,7 +69,8 @@ public function create(array $input): User ]; $user = User::create($data); - $participant = Participant::create(['user_id' => $user->id, 'code', $promoter_code]); + // $participant = Participant::create(['user_id' => $user->id, 'code', $promoter_code]); + $participant = Participant::create(['user_id' => $user->id]); $user->usertype()->associate($participant); $user->save(); diff --git a/app/Console/Commands/CreateDbSchema.php b/app/Console/Commands/CreateDbSchema.php index 5dbfbc26..f1f8ae01 100644 --- a/app/Console/Commands/CreateDbSchema.php +++ b/app/Console/Commands/CreateDbSchema.php @@ -26,9 +26,9 @@ class CreateDbSchema extends Command */ public function handle() { - $conn = DB::connectUsing("pgsql", [ + $conn = DB::connectUsing('pgsql', [ ...config('database.connections.pgsql'), - 'search_path' => "public", + 'search_path' => 'public', ]); $search_path = config('database.connections.pgsql.search_path'); diff --git a/app/Maintenance/EnvMaintenanceMode.php b/app/Maintenance/EnvMaintenanceMode.php index 56d37067..5830f2b8 100644 --- a/app/Maintenance/EnvMaintenanceMode.php +++ b/app/Maintenance/EnvMaintenanceMode.php @@ -7,42 +7,39 @@ class EnvMaintenanceMode implements MaintenanceMode { - public function __construct(protected Application $app) {} + public function __construct(protected Application $app) + { + } /** * Take the application down for maintenance. - * - * @param array $payload - * @return void */ - public function activate(array $payload): void { + public function activate(array $payload): void + { // } /** * Take the application out of maintenance. - * - * @return void */ - public function deactivate(): void { + public function deactivate(): void + { // } /** * Determine if the application is currently down for maintenance. - * - * @return bool */ - public function active(): bool { + public function active(): bool + { return $this->app->environment(['maintenance']); } /** * Get the data array which was provided when the application was placed into maintenance. - * - * @return array */ - public function data(): array { + public function data(): array + { return []; } } diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 1d3a6cfa..76254a95 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Traits\HasCV; +use App\Traits\HasReferralLink; use BaconQrCode\Renderer\Color\Rgb; use BaconQrCode\Renderer\Image\SvgImageBackEnd; use BaconQrCode\Renderer\ImageRenderer; @@ -20,6 +21,7 @@ class Participant extends Model { use HasCV; use HasFactory; + use HasReferralLink; /** * The attributes that are mass assignable. diff --git a/app/Models/StudentAssociation.php b/app/Models/StudentAssociation.php index 684a91a3..be58773a 100644 --- a/app/Models/StudentAssociation.php +++ b/app/Models/StudentAssociation.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Traits\HasReferralLink; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,6 +11,7 @@ class StudentAssociation extends Model { use HasFactory; + use HasReferralLink; /** * The attributes that are mass assignable. diff --git a/app/Models/StudentAssociationParticipation.php b/app/Models/StudentAssociationParticipation.php index ce057116..81e56746 100644 --- a/app/Models/StudentAssociationParticipation.php +++ b/app/Models/StudentAssociationParticipation.php @@ -36,4 +36,6 @@ public function toSearchableArray() return [ ]; } + + protected $table = 'edition_student_association'; } diff --git a/app/Traits/HasReferralLink.php b/app/Traits/HasReferralLink.php new file mode 100644 index 00000000..41064736 --- /dev/null +++ b/app/Traits/HasReferralLink.php @@ -0,0 +1,11 @@ + $association_name, 'email' => 'test@association.com', @@ -76,14 +74,13 @@ public function test_new_users_can_register_with_promoter_code(): void $test_association = StudentAssociation::create( [ 'user_id' => $association_user->id, - 'name' => $association_data['name'], - 'code' => $promoter_code + 'name' => $association_data['name'], + 'code' => $promoter_code, ] ); $association_user->usertype()->associate($test_association); $association_user->save(); - $response = $this->post('/register/', [ 'name' => $username, 'email' => 'test@example.com',