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 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',
]; ];
} }
} }

View File

@ -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;

View File

@ -297,34 +297,29 @@ 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 type: object
properties: properties:
user: last_name:
type: object type: string
properties: example: doe
last_name: name:
type: string type: string
example: doe example: jade
name: middle_name:
type: string type: string
example: jade example: john
middle_name: email:
type: string type: string
example: john example: jdoe@example.com
email: phone:
type: string type: string
example: jdoe@example.com example: '+000000'
phone:
type: string
example: '+000000'
password: password:
type: string type: string
example: 'very_strong_password123456' example: 'very_strong_password123456'