Skip to content

Commit

Permalink
internal(account): improve validation of main values
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 23, 2023
1 parent 7983ec7 commit 404b839
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controllers;

use CodeIgniter\Shield\Entities\User;
use CodeIgniter\Validation\Validation;

use App\Contracts\OwnedResource;
Expand All @@ -22,7 +23,7 @@ protected static function getModelName(): string {
return AccountModel::class;
}

protected static function makeCreateValidation(): Validation {
protected static function makeCreateValidation(User $owner): Validation {
$validation = static::makeValidation();
$individual_name = static::getIndividualName();
$table_name = static::getCollectiveName();
Expand All @@ -40,7 +41,12 @@ protected static function makeCreateValidation(): Validation {
"min_length[3]",
"max_length[255]",
"alpha_numeric_space",
"is_unique[$table_name.name]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."name",
"currency_id->$individual_name.currency_id"
])
])."]"
]);
$validation->setRule("$individual_name.kind", "description", [
"required",
Expand All @@ -52,7 +58,7 @@ protected static function makeCreateValidation(): Validation {
return $validation;
}

protected static function makeUpdateValidation(int $id): Validation {
protected static function makeUpdateValidation(User $owner, int $resource_id): Validation {
$validation = static::makeValidation();
$individual_name = static::getIndividualName();
$table_name = static::getCollectiveName();
Expand All @@ -62,7 +68,13 @@ protected static function makeUpdateValidation(int $id): Validation {
"min_length[3]",
"max_length[255]",
"alpha_numeric_space",
"is_unique[$table_name.name,id,$id]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."name",
"currency_id->$individual_name.currency_id"
]),
"id=$resource_id"
])."]"
]);

return $validation;
Expand Down

0 comments on commit 404b839

Please sign in to comment.