-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 12420-copy-advertisement-admin
- Loading branch information
Showing
33 changed files
with
874 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum DevelopmentProgramParticipationStatus | ||
{ | ||
case NOT_INTERESTED; | ||
case INTERESTED; | ||
case ENROLLED; | ||
case COMPLETED; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/app/GraphQL/Validators/CreateDevelopmentProgramInterestInputValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Validators; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Database\Helpers\ApiErrorEnums; | ||
use Illuminate\Validation\Rule; | ||
use Nuwave\Lighthouse\Validation\Validator; | ||
|
||
final class CreateDevelopmentProgramInterestInputValidator extends Validator | ||
{ | ||
/** | ||
* Return the validation rules. | ||
* | ||
* @return array<string, array<mixed>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
// developmentProgramId validated in the Create/UpdateCommunityInterestInputValidator | ||
'participationStatus' => [Rule::in(array_column(DevelopmentProgramParticipationStatus::cases(), 'name'))], | ||
'completionDate' => [ | ||
'date', | ||
'required_if:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
'prohibited_unless:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
], | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
'completionDate.required_if' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_REQUIRED, | ||
'completionDate.prohibited_unless' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_PROHIBITED, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
api/app/GraphQL/Validators/UpdateDevelopmentProgramInterestInputValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Validators; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Database\Helpers\ApiErrorEnums; | ||
use Illuminate\Validation\Rule; | ||
use Nuwave\Lighthouse\Validation\Validator; | ||
|
||
final class UpdateDevelopmentProgramInterestInputValidator extends Validator | ||
{ | ||
/** | ||
* Return the validation rules. | ||
* | ||
* @return array<string, array<mixed>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'participationStatus' => [Rule::in(array_column(DevelopmentProgramParticipationStatus::cases(), 'name'))], | ||
'completionDate' => [ | ||
'date', | ||
'required_if:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
'prohibited_unless:participationStatus,'.DevelopmentProgramParticipationStatus::COMPLETED->name, | ||
], | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
'completionDate.required_if' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_REQUIRED, | ||
'completionDate.prohibited_unless' => ApiErrorEnums::DEVELOPMENT_PROGRAM_COMPLETION_DATE_PROHIBITED, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
|
||
/** | ||
* Class DevelopmentProgram | ||
* | ||
* @property string $id | ||
* @property \Illuminate\Support\Carbon $created_at | ||
* @property ?\Illuminate\Support\Carbon $updated_at | ||
* @property ?\Illuminate\Support\Carbon $deleted_at | ||
* @property array $name | ||
* @property array $description_for_profile | ||
* @property array $description_for_nominations | ||
* @property string $community_id | ||
*/ | ||
class DevelopmentProgram extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $keyType = 'string'; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
*/ | ||
protected $casts = [ | ||
'name' => 'array', | ||
'description_for_profile' => 'array', | ||
'description_for_nominations' => 'array', | ||
]; | ||
|
||
/** @return BelongsTo<Community, $this> */ | ||
public function community(): BelongsTo | ||
{ | ||
return $this->belongsTo(Community::class); | ||
} | ||
|
||
/** @return BelongsToMany<Classification, $this> */ | ||
public function eligibleClassifications(): BelongsToMany | ||
{ | ||
return $this->belongsToMany(Classification::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\DevelopmentProgramParticipationStatus; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
/** | ||
* Class DevelopmentProgramInterest | ||
* | ||
* @property string $id | ||
* @property \Illuminate\Support\Carbon $created_at | ||
* @property ?\Illuminate\Support\Carbon $updated_at | ||
* @property ?\Illuminate\Support\Carbon $deleted_at | ||
* @property string $development_program_id | ||
* @property string $community_interest_id | ||
* @property string $participation_status | ||
* @property ?\Illuminate\Support\Carbon $completion_date | ||
*/ | ||
class DevelopmentProgramInterest extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $keyType = 'string'; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
*/ | ||
protected $casts = [ | ||
'participation_status' => DevelopmentProgramParticipationStatus::class, | ||
'completion_date' => 'datetime', | ||
]; | ||
|
||
/** @return BelongsTo<CommunityInterest, $this> */ | ||
public function communityInterest(): BelongsTo | ||
{ | ||
return $this->belongsTo(CommunityInterest::class); | ||
} | ||
|
||
/** @return BelongsTo<DevelopmentProgram, $this> */ | ||
public function developmentProgram(): BelongsTo | ||
{ | ||
return $this->belongsTo(DevelopmentProgram::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Classification; | ||
use App\Models\Community; | ||
use App\Models\DevelopmentProgram; | ||
use Database\Helpers\FactoryHelpers; | ||
use ErrorException; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class DevelopmentProgramFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = DevelopmentProgram::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'name' => FactoryHelpers::toFakeLocalizedString($this->faker->company()), | ||
'description_for_profile' => FactoryHelpers::toFakeLocalizedString($this->faker->sentence()), | ||
'description_for_nominations' => FactoryHelpers::toFakeLocalizedString($this->faker->sentence()), | ||
'community_id' => function () { | ||
$community = Community::inRandomOrder()->firstOr(fn () => Community::factory()->withWorkStreams()->create()); | ||
|
||
return $community->id; | ||
}, | ||
]; | ||
} | ||
|
||
public function configure() | ||
{ | ||
return $this | ||
->afterMaking(function (DevelopmentProgram $model) { | ||
// https://laravel.com/docs/10.x/eloquent-factories#belongs-to-relationships | ||
if (is_null($model->community_id)) { | ||
throw new ErrorException('community_id must be set to use this factory. Try calling this factory with the `for` method to specify the parent community.'); | ||
} | ||
}); | ||
} | ||
|
||
public function withEligibleClassifications(?int $min = 1, ?int $max = 3) | ||
{ | ||
$count = $this->faker->numberBetween($min, $max); | ||
|
||
return $this->afterCreating(function (DevelopmentProgram $program) use ($count) { | ||
$classifications = Classification::inRandomOrder()->limit($count)->get(); | ||
$program->eligibleClassifications()->sync($classifications); | ||
}); | ||
} | ||
} |
Oops, something went wrong.