Skip to content

Commit

Permalink
fix(user): pass the tables to validation maker
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Dec 3, 2023
1 parent bd58a50 commit 39c1d33
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected static function getIndividualName(): string {

public function update() {
$current_user = auth()->user();
$validation = static::makeIdentityValidation($current_user->id);
$validation = static::makeIdentityValidation($current_user->id, $this->tables);

$request_document = $this->request->getJson(true);
$is_success = $validation->run($request_document);
Expand Down Expand Up @@ -71,17 +71,22 @@ public function updatePassword() {
throw new InvalidRequest($validation);
}

private static function makeIdentityValidation(int $current_user_id): Validation {
private static function makeIdentityValidation(
int $current_user_id,
array $tables
): Validation {
$validation = single_service("validation");
$individual_name = static::getIndividualName();

$usernameRules = array_merge(
config("AuthSession")->usernameValidationRules,
[sprintf("is_unique[%s.username,id,$current_user_id]", $this->tables["users"])]
[sprintf("is_unique[%s.username,id,$current_user_id]",
$tables["users"])]
);
$emailRules = array_merge(
config("AuthSession")->emailValidationRules,
[sprintf("is_unique[%s.secret,id,$current_user_id]", $this->tables["identities"])]
[sprintf("is_unique[%s.secret,id,$current_user_id]",
$tables["identities"])]
);

$validation->setRule($individual_name, "user", [
Expand Down

0 comments on commit 39c1d33

Please sign in to comment.