fix(surveyor): optimasi save data inpeksi
This commit is contained in:
@@ -167,6 +167,23 @@ class SurveyorController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validatedData = $request->all();
|
||||
|
||||
$fotoTypes = [
|
||||
'foto_gistaru',
|
||||
'foto_bhumi',
|
||||
'foto_argis_region',
|
||||
'foto_tempat',
|
||||
'foto_sentuh_tanahku',
|
||||
'upload_gs'
|
||||
];
|
||||
|
||||
// Hapus data foto dari $validatedData
|
||||
foreach ($fotoTypes as $fotoType) {
|
||||
if (isset($validatedData[$fotoType])) {
|
||||
unset($validatedData[$fotoType]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->inspeksiService->storeInspeksi($validatedData, $request->input('type'), $request);
|
||||
|
||||
if ($result['success']) {
|
||||
@@ -2028,9 +2045,9 @@ class SurveyorController extends Controller
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
||||
// abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
// if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
||||
// abort(403, 'Sorry! You are not allowed to view users.');
|
||||
// }
|
||||
|
||||
$query = Permohonan::query();
|
||||
$query = $query->orderBy('nomor_registrasi', 'desc');
|
||||
@@ -2099,7 +2116,7 @@ class SurveyorController extends Controller
|
||||
|
||||
public function dataForDatatablesData(Request $request, $type)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('jenis_aset.view')) {
|
||||
if (is_null(auth()->user()) || !$this->user->can('jenis_aset.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
@@ -2818,4 +2835,73 @@ class SurveyorController extends Controller
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadFileFoto(Request $request, $url)
|
||||
{
|
||||
|
||||
// dd($request->all());
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))
|
||||
->where('dokument_id', $request->input('dokument_id'))
|
||||
->first();
|
||||
|
||||
$fotoTypes = [
|
||||
'foto_gistaru',
|
||||
'foto_bhumi',
|
||||
'foto_argis_region',
|
||||
'foto_tempat',
|
||||
'foto_sentuh_tanahku',
|
||||
'upload_gs'
|
||||
];
|
||||
|
||||
if (!in_array($url, $fotoTypes)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid key for upload'
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
||||
$existingData = $inspeksi ? json_decode($inspeksi->data_form, true) : [];
|
||||
$existingData = $existingData ?? [];
|
||||
|
||||
|
||||
$factData = $existingData;
|
||||
if ($request->hasFile('file')) {
|
||||
$file = $request->file('file');
|
||||
$filePath = $file->store('uploads', 'public');
|
||||
$uploadedPath = str_replace('public/', '', $filePath);
|
||||
|
||||
|
||||
$factData[$url] = $uploadedPath;
|
||||
|
||||
|
||||
$existingData = $factData;
|
||||
if ($inspeksi) {
|
||||
$inspeksi->data_form = json_encode($existingData);
|
||||
$inspeksi->save();
|
||||
} else {
|
||||
Inspeksi::create([
|
||||
'permohonan_id' => $request->input('permohonan_id'),
|
||||
'dokument_id' => $request->input('document_id'),
|
||||
'data_form' => json_encode($existingData),
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No file uploaded for the given key'
|
||||
], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Berhasil upload file foto',
|
||||
'data' => [
|
||||
'key' => $url,
|
||||
'path' => $factData[$url] ?? null
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user