Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LP-130 employer information #16

Merged
merged 13 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
90 changes: 47 additions & 43 deletions src/Http/Requests/RegistrationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down
4 changes: 4 additions & 0 deletions src/Http/Requests/StoreUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
4 changes: 4 additions & 0 deletions src/Http/Requests/UpdateUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
39 changes: 35 additions & 4 deletions src/Http/Resources/UserCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -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 = [
Expand All @@ -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
*/
Expand Down Expand Up @@ -111,7 +142,7 @@ public function with(Request $request): array
];
}

private function formatMediaCollection($collection)
private function formatMediaCollection($collection): array
{
$data = [];

Expand Down
12 changes: 9 additions & 3 deletions src/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -113,7 +119,7 @@ public function toArray($request)
return array_merge($data, $profile_data);
}

private function formatMediaCollection($collection)
private function formatMediaCollection($collection): array
{
$data = [];

Expand Down
4 changes: 4 additions & 0 deletions src/Services/ProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down