change strcture controller becuse repet some code in 3 file and get same code in model
This commit is contained in:
@@ -17,8 +17,6 @@ use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Harim;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
|
||||
class TechnicalDeputyController extends Controller
|
||||
@@ -40,113 +38,58 @@ class TechnicalDeputyController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function confirmRequest(ConfirmRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::CONFIRM->value;
|
||||
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_TAVASOT_MODIR_KOL->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::CONFIRM->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_TAVASOT_MODIR_KOL->value,
|
||||
'state_name' => HarimStates::BARESI_TAVASOT_MODIR_KOL->label(),
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function referRequest(ReferRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::REFER->value;
|
||||
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_TAVASOT_DAFTAR_HARIM->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::REFER->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_TAVASOT_DAFTAR_HARIM->value,
|
||||
'state_name' => HarimStates::BARESI_TAVASOT_DAFTAR_HARIM->label(),
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function confirmRoadAccess(ConfirmRoadAccessRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::CONFIRM->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MODIR_KOL->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::CONFIRM->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MODIR_KOL->value,
|
||||
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MODIR_KOL->label(),
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function referRoadAccess(ReferRoadAccessRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::REFER->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::REFER->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->value,
|
||||
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->label(),
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
@@ -155,4 +98,30 @@ class TechnicalDeputyController extends Controller
|
||||
{
|
||||
return $this->successResponse($harim->load('histories'));
|
||||
}
|
||||
|
||||
public function referPayment(ReferPaymentRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::REFER->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->value,
|
||||
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->label(),
|
||||
]
|
||||
);
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function confirmPayment(ConfirmPaymentRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::CONFIRM->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL->value,
|
||||
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL->label(),
|
||||
]
|
||||
);
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user