refactor: fix up /api/users/private/edit/{id} a little bit

This commit is contained in:
b1ek 2024-08-30 17:49:54 +10:00
parent c67c96cf92
commit d85c62eedc
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 24 additions and 35 deletions

View File

@ -16,19 +16,12 @@ class UserEditRequest extends AuthorizedRequest
public function rules(): array
{
return [
'user.last_name' => ['string'],
'user.name' => ['string'],
'user.middle_name' => ['string'],
'user.email' => ['email'],
'user.phone' => ['string', 'regex:'.User::PHONE_REGEX],
'user' => 'required',
'last_name' => ['string'],
'name' => ['string'],
'middle_name' => ['string'],
'email' => ['email'],
'phone' => ['string', 'regex:'.User::PHONE_REGEX],
'password' => [Password::min(1)->rules([new ZxcvbnRule])],
'user.email_verified_at' => 'prohibited',
'user.created_at' => 'prohibited',
'user.updated_at' => 'prohibited',
'user.deleted_at' => 'prohibited',
'user.id' => 'prohibited',
];
}
}

View File

@ -87,9 +87,10 @@ class UserService
if (array_key_exists('password', $data)) {
$this->setPassword(['email' => $user['email'], 'password' => $data['password']]);
unset($data['password']);
}
$user->fill($data['user']);
$user->fill($data);
$user->save();
return $user;

View File

@ -297,34 +297,29 @@ paths:
description: User not found
requestBody:
description: |-
All fields of `user` are optional. If a field is specified, the database record will change to the field's value.
All fields are optional. If a field is specified, the database record will change to the field's value.
`password` is optional, only if you want to update the password.
Note: updating password will not revoke all current sessions of the user
Note: updating the password will not revoke all current sessions of the user
content:
application/json:
schema:
type: object
properties:
user:
type: object
properties:
last_name:
type: string
example: doe
name:
type: string
example: jade
middle_name:
type: string
example: john
email:
type: string
example: jdoe@example.com
phone:
type: string
example: '+000000'
last_name:
type: string
example: doe
name:
type: string
example: jade
middle_name:
type: string
example: john
email:
type: string
example: jdoe@example.com
phone:
type: string
example: '+000000'
password:
type: string
example: 'very_strong_password123456'