refactor: fix up /api/users/private/edit/{id} a little bit
This commit is contained in:
parent
c67c96cf92
commit
d85c62eedc
|
@ -16,19 +16,12 @@ class UserEditRequest extends AuthorizedRequest
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'user.last_name' => ['string'],
|
'last_name' => ['string'],
|
||||||
'user.name' => ['string'],
|
'name' => ['string'],
|
||||||
'user.middle_name' => ['string'],
|
'middle_name' => ['string'],
|
||||||
'user.email' => ['email'],
|
'email' => ['email'],
|
||||||
'user.phone' => ['string', 'regex:'.User::PHONE_REGEX],
|
'phone' => ['string', 'regex:'.User::PHONE_REGEX],
|
||||||
'user' => 'required',
|
|
||||||
'password' => [Password::min(1)->rules([new ZxcvbnRule])],
|
'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',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,10 @@ class UserService
|
||||||
|
|
||||||
if (array_key_exists('password', $data)) {
|
if (array_key_exists('password', $data)) {
|
||||||
$this->setPassword(['email' => $user['email'], 'password' => $data['password']]);
|
$this->setPassword(['email' => $user['email'], 'password' => $data['password']]);
|
||||||
|
unset($data['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->fill($data['user']);
|
$user->fill($data);
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
|
|
|
@ -297,17 +297,12 @@ paths:
|
||||||
description: User not found
|
description: User not found
|
||||||
requestBody:
|
requestBody:
|
||||||
description: |-
|
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 the password will not revoke all current sessions of the user
|
||||||
|
|
||||||
Note: updating password will not revoke all current sessions of the user
|
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
user:
|
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
last_name:
|
last_name:
|
||||||
|
|
Loading…
Reference in New Issue