Skip to content

Commit

Permalink
Added HasReferralLink trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Naapperas committed Aug 14, 2024
1 parent 159cd64 commit 2253be2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
5 changes: 4 additions & 1 deletion app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,6 +57,7 @@ public function create(array $input): User
$student_association->save();
}
}
*/
}

$data = [
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/CreateDbSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
25 changes: 11 additions & 14 deletions app/Maintenance/EnvMaintenanceMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}
2 changes: 2 additions & 0 deletions app/Models/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@ class Participant extends Model
{
use HasCV;
use HasFactory;
use HasReferralLink;

/**
* The attributes that are mass assignable.
Expand Down
2 changes: 2 additions & 0 deletions app/Models/StudentAssociation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -10,6 +11,7 @@
class StudentAssociation extends Model
{
use HasFactory;
use HasReferralLink;

/**
* The attributes that are mass assignable.
Expand Down
2 changes: 2 additions & 0 deletions app/Models/StudentAssociationParticipation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public function toSearchableArray()
return [
];
}

protected $table = 'edition_student_association';
}
11 changes: 11 additions & 0 deletions app/Traits/HasReferralLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Traits;

trait HasReferralLink
{
public function get_referral_link(): string
{
return 'TODO: implement this';
}
}
13 changes: 5 additions & 8 deletions tests/Feature/ReferalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Tests\Feature;

use App\Models\User;
use App\Models\Participant;
use App\Models\StudentAssociation;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Illuminate\Support\Facades\Hash;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
use Tests\TestCase;

class ReferalTest extends TestCase
{
Expand Down Expand Up @@ -63,7 +62,6 @@ public function test_new_users_can_register_with_promoter_code(): void
$promoter_code = 'NUC-1';
$association_name = 'Test Association';


$association_data = [
'name' => $association_name,
'email' => '[email protected]',
Expand All @@ -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' => '[email protected]',
Expand Down

0 comments on commit 2253be2

Please sign in to comment.