diff --git a/config/auth.php b/config/auth.php index 8cf3b05..037923d 100644 --- a/config/auth.php +++ b/config/auth.php @@ -187,6 +187,10 @@ 'documents.*.type' => ['string', 'required'], 'documents.*.back' => ['string', 'required_without:documents.*.front'], 'documents.*.front' => ['string', 'required_without:documents.*.back'], + 'employer' => ['array', 'nullable'], + 'employer.employer_name' => ['string', 'nullable'], + 'employer.company_address' => ['string', 'nullable'], + 'employer.company_registration_number' => ['string', 'nullable'], 'proof_of_address' => ['array', 'required', 'min:1'], 'proof_of_address.*.type' => ['string', 'required'], 'proof_of_address.*.back' => ['string', 'required_without:proof_of_address.*.front'], @@ -238,6 +242,22 @@ //'middleware' => ['auth:sanctum'], 'middleware' => [], + /* + |-------------------------------------------------------------------------- + | Constant + |-------------------------------------------------------------------------- + | + | This value will be used across systems where a constant instance is needed + */ + + 'proof_of_address_types' => [ + 'tenancy_contract' => 'Tenancy Contract', + 'utility_bill' => 'Utility Bill', + 'bank_statement' => 'Bank Statement', + 'credit_card_statement' => 'Credit Card Statement', + 'telephone_bill' => 'Telephone Bill', + ], + /* |-------------------------------------------------------------------------- | Repositories diff --git a/src/Http/Controllers/UserController.php b/src/Http/Controllers/UserController.php index 48d5d02..4454be2 100644 --- a/src/Http/Controllers/UserController.php +++ b/src/Http/Controllers/UserController.php @@ -265,6 +265,7 @@ public function export(IndexUserRequest $request): JsonResponse * * @lrd:end * + * @param ImportUserRequest $request * @return UserCollection|JsonResponse */ public function import(ImportUserRequest $request): UserCollection|JsonResponse @@ -290,6 +291,7 @@ public function import(ImportUserRequest $request): UserCollection|JsonResponse * @lrd:end * * @param int|string $id + * @param string $field * @param UserAuthResetRequest $request * @return JsonResponse */ diff --git a/src/Http/Requests/RegistrationRequest.php b/src/Http/Requests/RegistrationRequest.php index 8002dce..f173b91 100644 --- a/src/Http/Requests/RegistrationRequest.php +++ b/src/Http/Requests/RegistrationRequest.php @@ -23,50 +23,54 @@ public function authorize(): bool public function rules(): array { $rules = config('fintech.auth.register_rules', [ - //user - 'name' => ['required', 'string', 'min:2', 'max:255'], - 'mobile' => ['required', 'string', 'min:10'], - 'email' => ['required', 'string', 'email:rfc,dns', 'min:2', 'max:255'], - 'pin' => ['required', 'string', 'min:4', 'max:16'], - 'app_version' => ['nullable', 'string'], - 'fcm_token' => ['nullable', 'string'], - 'language' => ['nullable', 'string'], - 'currency' => ['nullable', 'string'], + //user + 'name' => ['required', 'string', 'min:2', 'max:255'], + 'mobile' => ['required', 'string', 'min:10'], + 'email' => ['required', 'string', 'email:rfc,dns', 'min:2', 'max:255'], + 'pin' => ['required', 'string', 'min:4', 'max:16'], + 'app_version' => ['nullable', 'string'], + 'fcm_token' => ['nullable', 'string'], + 'language' => ['nullable', 'string'], + 'currency' => ['nullable', 'string'], - //profile - 'father_name' => ['string', 'nullable'], - 'mother_name' => ['string', 'nullable'], - 'gender' => ['string', 'nullable'], - 'marital_status' => ['string', 'nullable'], - 'occupation' => ['string', 'nullable'], - 'source_of_income' => ['string', 'nullable'], - 'id_type' => ['string', 'nullable'], - 'id_no' => ['string', 'nullable'], - 'id_issue_country' => ['string', 'nullable'], - 'id_expired_at' => ['string', 'nullable'], - 'id_issue_at' => ['string', 'nullable'], - 'photo' => ['string', 'nullable'], - 'documents' => ['array', 'required', 'min:1'], - 'documents.*.type' => ['string', 'required'], - 'documents.*.back' => ['string', 'required_without:documents.*.front'], - 'documents.*.front' => ['string', 'required_without:documents.*.back'], - 'proof_of_address' => ['array', 'required', 'min:1'], - 'proof_of_address.*.type' => ['string', 'required'], - 'proof_of_address.*.front' => ['string', 'required_without:proof_of_address.*.back'], - 'proof_of_address.*.back' => ['string', 'required_without:proof_of_address.*.front'], - 'date_of_birth' => ['date', 'nullable'], - 'permanent_address' => ['string', 'nullable'], - 'city_id' => ['integer', 'nullable'], - 'state_id' => ['integer', 'nullable'], - 'country_id' => ['integer', 'nullable'], - 'post_code' => ['string', 'nullable'], - 'present_address' => ['string', 'nullable'], - 'present_city_id' => ['integer', 'nullable'], - 'present_state_id' => ['integer', 'nullable'], - 'present_country_id' => ['integer', 'nullable'], - 'present_post_code' => ['string', 'nullable'], - 'nationality' => ['string', 'nullable'], - ]); + //profile + 'father_name' => ['string', 'nullable'], + 'mother_name' => ['string', 'nullable'], + 'gender' => ['string', 'nullable'], + 'marital_status' => ['string', 'nullable'], + 'occupation' => ['string', 'nullable'], + 'source_of_income' => ['string', 'nullable'], + 'id_type' => ['string', 'nullable'], + 'id_no' => ['string', 'nullable'], + 'id_issue_country' => ['string', 'nullable'], + 'id_expired_at' => ['string', 'nullable'], + 'id_issue_at' => ['string', 'nullable'], + 'photo' => ['string', 'nullable'], + 'documents' => ['array', 'required', 'min:1'], + 'documents.*.type' => ['string', 'required'], + 'documents.*.back' => ['string', 'required_without:documents.*.front'], + 'documents.*.front' => ['string', 'required_without:documents.*.back'], + 'employer' => ['array', 'nullable'], + 'employer.company_name' => ['string', 'nullable'], + 'employer.company_address' => ['string', 'nullable'], + 'employer.company_registration_number' => ['string', 'nullable'], + 'proof_of_address' => ['array', 'required', 'min:1'], + 'proof_of_address.*.type' => ['string', 'required'], + 'proof_of_address.*.front' => ['string', 'required_without:proof_of_address.*.back'], + 'proof_of_address.*.back' => ['string', 'required_without:proof_of_address.*.front'], + 'date_of_birth' => ['date', 'nullable'], + 'permanent_address' => ['string', 'nullable'], + 'city_id' => ['integer', 'nullable'], + 'state_id' => ['integer', 'nullable'], + 'country_id' => ['integer', 'nullable'], + 'post_code' => ['string', 'nullable'], + 'present_address' => ['string', 'nullable'], + 'present_city_id' => ['integer', 'nullable'], + 'present_state_id' => ['integer', 'nullable'], + 'present_country_id' => ['integer', 'nullable'], + 'present_post_code' => ['string', 'nullable'], + 'nationality' => ['string', 'nullable'], + ]); $rules[config('fintech.auth.auth_field', 'login_id')] = config('fintech.auth.auth_field_rules', ['required', 'string', 'min:6', 'max:255']); diff --git a/src/Http/Requests/StoreUserRequest.php b/src/Http/Requests/StoreUserRequest.php index a2159da..3be0401 100644 --- a/src/Http/Requests/StoreUserRequest.php +++ b/src/Http/Requests/StoreUserRequest.php @@ -50,6 +50,10 @@ public function rules(): array 'documents.*.type' => ['string', 'required'], 'documents.*.back' => ['string', 'required_without:documents.*.front'], 'documents.*.front' => ['string', 'required_without:documents.*.back'], + 'employer' => ['array', 'nullable'], + 'employer.employer_name' => ['string', 'nullable'], + 'employer.company_address' => ['string', 'nullable'], + 'employer.company_registration_number' => ['string', 'nullable'], 'proof_of_address' => ['array', 'required', 'min:1'], 'proof_of_address.*.type' => ['string', 'required'], 'proof_of_address.*.front' => ['string', 'required_without:proof_of_address.*.back'], diff --git a/src/Http/Requests/UpdateUserRequest.php b/src/Http/Requests/UpdateUserRequest.php index ea97cdc..6a70959 100644 --- a/src/Http/Requests/UpdateUserRequest.php +++ b/src/Http/Requests/UpdateUserRequest.php @@ -50,6 +50,10 @@ public function rules(): array 'documents.*.type' => ['string', 'required'], 'documents.*.back' => ['string', 'required_without:documents.*.front'], 'documents.*.front' => ['string', 'required_without:documents.*.back'], + 'employer' => ['array', 'nullable'], + 'employer.company_name' => ['string', 'nullable'], + 'employer.company_address' => ['string', 'nullable'], + 'employer.company_registration_number' => ['string', 'nullable'], 'proof_of_address' => ['array', 'required', 'min:1'], 'proof_of_address.*.type' => ['string', 'required'], 'proof_of_address.*.back' => ['string', 'required_without:proof_of_address.*.front'], diff --git a/src/Http/Resources/UserCollection.php b/src/Http/Resources/UserCollection.php index be3e80e..fa3e250 100644 --- a/src/Http/Resources/UserCollection.php +++ b/src/Http/Resources/UserCollection.php @@ -2,13 +2,44 @@ namespace Fintech\Auth\Http\Resources; +use Carbon\Carbon; use Fintech\Auth\Models\Profile; use Fintech\Core\Facades\Core; use Fintech\Core\Supports\Constant; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\ResourceCollection; +use Illuminate\Support\Collection; use Spatie\MediaLibrary\MediaCollections\Models\Media; +/** + * @property mixed $roles + */ +/** + * Class UserResource + * @package Fintech\Auth\Http\Resources + * + * @property-read int $id + * @property-read string $name + * @property-read string $mobile + * @property-read string $email + * @property-read string $login_id + * @property-read string $status + * @property-read string $language + * @property-read string $currency + * @property-read string $app_version + * @property-read float $total_balance + * @property-read Collection $roles + * @property-read Profile|null $profile + * @property-read Carbon $email_verified_at + * @property-read Carbon $mobile_verified_at + * @property-read Carbon $created_at + * @property-read Carbon $updated_at + * @property mixed $parent + * @property mixed $parent_id + * @property mixed $links + * @method getKey() + * @method getFirstMediaUrl(string $string) + */ class UserCollection extends ResourceCollection { /** @@ -17,7 +48,7 @@ class UserCollection extends ResourceCollection * @param Request $request * @return array */ - public function toArray($request) + public function toArray(Request $request): array { return $this->collection->map(function ($user) { $data = [ @@ -33,12 +64,12 @@ public function toArray($request) 'language' => $user->language ?? null, 'currency' => $user->currency ?? null, 'app_version' => $user->app_version ?? null, - 'roles' => ($user->roles) ? $user->roles->pluck('name')->toArray() : [], + 'roles' => ($user->roles) ? $user->roles->toArray() : [], 'links' => $user->links, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, ]; - + unset($data['roles'][0]['links'],$data['roles'][0]['pivot'],$data['roles'][0]['permissions']); /** * @var Profile $profile */ @@ -111,7 +142,7 @@ public function with(Request $request): array ]; } - private function formatMediaCollection($collection) + private function formatMediaCollection($collection): array { $data = []; diff --git a/src/Http/Resources/UserResource.php b/src/Http/Resources/UserResource.php index d7da7e4..9d75d7a 100644 --- a/src/Http/Resources/UserResource.php +++ b/src/Http/Resources/UserResource.php @@ -30,6 +30,11 @@ * @property-read Carbon $mobile_verified_at * @property-read Carbon $created_at * @property-read Carbon $updated_at + * @property mixed $parent + * @property mixed $parent_id + * @property mixed $links + * @method getKey() + * @method getFirstMediaUrl(string $string) */ class UserResource extends JsonResource { @@ -39,7 +44,7 @@ class UserResource extends JsonResource * @param Request $request * @return array */ - public function toArray($request) + public function toArray(Request $request): array { $data = [ 'id' => $this->getKey() ?? null, @@ -54,11 +59,12 @@ public function toArray($request) 'language' => $this->language ?? null, 'currency' => $this->currency ?? null, 'app_version' => $this->app_version ?? null, - 'roles' => ($this->roles) ? $this->roles->pluck('name', 'id')->toArray() : [], + 'roles' => ($this->roles) ? $this->roles->toArray() : [], 'links' => $this->links, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; + unset($data['roles'][0]['links'],$data['roles'][0]['pivot'],$data['roles'][0]['permissions']); /** * @var Profile $profile @@ -113,7 +119,7 @@ public function toArray($request) return array_merge($data, $profile_data); } - private function formatMediaCollection($collection) + private function formatMediaCollection($collection): array { $data = []; diff --git a/src/Services/ProfileService.php b/src/Services/ProfileService.php index b9e6a38..6554f15 100644 --- a/src/Services/ProfileService.php +++ b/src/Services/ProfileService.php @@ -123,6 +123,10 @@ private function formatDataFromInput($inputs, bool $forCreate = false) unset($data['nationality']); } + if (isset($inputs['employer'])) { + $data['user_profile_data']['employer'] = $inputs['employer']; + unset($data['employer']); + } return $data; }