Skip to content

Commit

Permalink
internal(currency): 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 1a3a078 commit 17199ef
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions app/Controllers/CurrencyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,34 @@ protected static function makeCreateValidation(): Validation {
$individual_name = static::getIndividualName();
$table_name = static::getCollectiveName();

$current_user = auth()->user();
$user_id = $current_user->id;

$validation->setRule("$individual_name.code", "code", [
"required",
"min_length[2]",
"max_length[255]",
"alpha_numeric",
"is_unique[$table_name.code]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."code",
"name->$individual_name.name",
"user_id=$user_id"
])
])."]"
]);
$validation->setRule("$individual_name.name", "name", [
"required",
"min_length[2]",
"max_length[255]",
"alpha_numeric_space",
"is_unique[$table_name.name]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."name",
"code->$individual_name.code",
"user_id=$user_id"
])
])."]"
]);

return $validation;
Expand All @@ -49,19 +64,36 @@ protected static function makeUpdateValidation(int $id): Validation {
$individual_name = static::getIndividualName();
$table_name = static::getCollectiveName();

$current_user = auth()->user();
$user_id = $current_user->id;

$validation->setRule("$individual_name.code", "code", [
"required",
"min_length[2]",
"max_length[255]",
"alpha_numeric",
"is_unique[$table_name.code,id,$id]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."code",
"name->$individual_name.name",
"user_id=$user_id"
]),
"id=$id"
])."]"
]);
$validation->setRule("$individual_name.name", "name", [
"required",
"min_length[2]",
"max_length[255]",
"alpha_numeric_space",
"is_unique[$table_name.name,id,$id]"
"is_unique_compositely[".implode(",", [
implode("|", [
static::getModelName().":"."name",
"code->$individual_name.code",
"user_id=$user_id"
]),
"id=$id"
])."]"
]);

return $validation;
Expand Down

0 comments on commit 17199ef

Please sign in to comment.