wip
This commit is contained in:
@@ -9,15 +9,20 @@ use App\Modules\LoanOrder\Controllers\Requests\LoanOrderStoreRequest;
|
||||
use App\Modules\LoanOrder\Controllers\Resources\LoanOrderIndexResource;
|
||||
use App\Modules\LoanOrder\Controllers\Resources\LoanOrderShowResource;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use Dedoc\Scramble\Attributes\Group;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Group('Sargytlar - Karz - Karz sargytlary Mobile')]
|
||||
class LoanOrderController extends Controller
|
||||
{
|
||||
/**
|
||||
* LIST* Loan orders.
|
||||
*
|
||||
* `Karz sargytlary list`-leri list gornushde gelyar. https://online.tbbank.gov.tm/work-place/resources/loan-order-mobiles dan `Label` gorup bilyan. `BaseAppEnum` dan gerek yerlerini match edishene gora alyan.
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@@ -31,38 +36,51 @@ class LoanOrderController extends Controller
|
||||
|
||||
/**
|
||||
* SAVE* Loan order.
|
||||
*
|
||||
* `Karz sargytlary save`. Example bar, online panelkadan gorup hem bilersin. Update store daky yaly, yone oz ugratyan zadyn update bolyar, eger ugratmasaň, üýtgemez.
|
||||
*/
|
||||
public function store(LoanOrderStoreRequest $request): JsonResponse
|
||||
public function store(LoanOrderStoreRequest $request, LoanOrder $loanOrder): JsonResponse
|
||||
{
|
||||
Log::channel('form_logs')->info('loan-order-store-request', $request->all());
|
||||
Log::channel('form_logs')->info('loan-order-update-request', $request->all());
|
||||
|
||||
$data = $request->validated();
|
||||
|
||||
$months = DateHelperRepository::monthsAsNumber();
|
||||
$years = DateHelperRepository::yearsUntil();
|
||||
|
||||
$data['card_month'] = indexByValue($request->card_month, $months);
|
||||
$data['card_year'] = indexByValue($request->card_year, $years);
|
||||
if ($request->filled('card_month')) {
|
||||
$data['card_month'] = indexByValue($request->card_month, $months);
|
||||
}
|
||||
|
||||
$data['guarantor_card_month'] = indexByValue($request->guarantor_card_month, $months);
|
||||
$data['guarantor_card_year'] = indexByValue($request->guarantor_card_year, $years);
|
||||
if ($request->filled('card_year')) {
|
||||
$data['card_year'] = indexByValue($request->card_year, $years);
|
||||
}
|
||||
|
||||
$data['guarantor_2_card_month'] = indexByValue($request->guarantor_2_card_month, $months);
|
||||
$data['guarantor_2_card_year'] = indexByValue($request->guarantor_2_card_year, $years);
|
||||
if ($request->filled('guarantor_card_month')) {
|
||||
$data['guarantor_card_month'] = indexByValue($request->guarantor_card_month, $months);
|
||||
}
|
||||
|
||||
LoanOrder::forceCreate([
|
||||
...$data,
|
||||
...[
|
||||
'user_id' => auth()->id(),
|
||||
'status' => OrderRepo::PENDING,
|
||||
'source' => OrderRepo::MOBILE_DEVICE,
|
||||
],
|
||||
...$this->uploadedFiles($request),
|
||||
]);
|
||||
if ($request->filled('guarantor_card_year')) {
|
||||
$data['guarantor_card_year'] = indexByValue($request->guarantor_card_year, $years);
|
||||
}
|
||||
|
||||
if ($request->filled('guarantor_2_card_month')) {
|
||||
$data['guarantor_2_card_month'] = indexByValue($request->guarantor_2_card_month, $months);
|
||||
}
|
||||
|
||||
if ($request->filled('guarantor_2_card_year')) {
|
||||
$data['guarantor_2_card_year'] = indexByValue($request->guarantor_2_card_year, $years);
|
||||
}
|
||||
|
||||
$data += $this->uploadedFiles($request);
|
||||
|
||||
Model::unguarded(function () use ($loanOrder, $data) {
|
||||
$loanOrder->update($data);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'message' => __('Successfully created'),
|
||||
], 201);
|
||||
'message' => __('Successfully updates'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,16 +90,21 @@ class LoanOrderController extends Controller
|
||||
*/
|
||||
public function uploadedFiles(Request $request): array
|
||||
{
|
||||
return [
|
||||
'passport_one' => Str::after($request->file('passport_one')->store('public'), 'public/'),
|
||||
'passport_two' => Str::after($request->file('passport_two')->store('public'), 'public/'),
|
||||
'passport_three' => Str::after($request->file('passport_three')->store('public'), 'public/'),
|
||||
'passport_four' => Str::after($request->file('passport_four')->store('public'), 'public/'),
|
||||
];
|
||||
$files = [];
|
||||
|
||||
foreach (['passport_one', 'passport_two', 'passport_three', 'passport_four'] as $field) {
|
||||
if ($request->hasFile($field)) {
|
||||
$files[$field] = Str::after($request->file($field)->store('public'), 'public/');
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* SHOW* Loan order
|
||||
*
|
||||
* `Karz sargytlary show by id`. ID ugradyp alyan route -da. Base App Enum-lardan peydalan. Panelkadan gor.
|
||||
*/
|
||||
public function show(LoanOrder $loanOrder): JsonResponse
|
||||
{
|
||||
@@ -94,6 +117,8 @@ class LoanOrderController extends Controller
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* `Karz sargytlary update`. ID ugradyp `route`-da update edip bilyan. Base App Enum-lardan peydalan. Panelkadan gor.
|
||||
*/
|
||||
public function update(Request $request): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user