🔧 refactor(inspeksi): gunakan updateOrCreate & perbaikan kode
- Ganti `Inspeksi::create()` → `updateOrCreate()` di PenilaiController (2x) & SurveyorController (1x) dengan kondisi upsert (permohonan_id + dokument_id)
- Tambah logging di SaveFormInspesksiService.php (`Log::info`) untuk debugging & validasi action kosong
- Perbaiki error handling dengan pesan lebih informatif `'Gagal menyimpan data : '.$e->getMessage()`
- Refaktor parsing action memakai array_map & array_filter agar lebih efisien
- Rapikan kode: hapus baris kosong tidak perlu & improve readability
- Perbaiki urutan class CSS di beberapa Blade view (rap-penilai, penilai/index, surveyor/inspeksi)
- Perbaiki XSS di rap-penilai.blade.php dengan `{!! json_encode($dokumen->address ?? '') !!}`
- Tingkatkan integritas database: cegah duplikasi data inspeksi via updateOrCreate()
- Tambah keamanan & maintainability: logging, validasi input, perbaikan format, serta pembersihan kode lama
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Illuminate\Http\Request;
|
||||
use \Illuminate\Support\Facades\Log;
|
||||
|
||||
class SaveFormInspesksiService
|
||||
{
|
||||
@@ -20,6 +21,7 @@ class SaveFormInspesksiService
|
||||
$inspeksi->name = $request->input('type');
|
||||
|
||||
$processedData = $this->getActionSpecificRules($validatedData, $type, $request, $inspeksi);
|
||||
Log::info($processedData);
|
||||
|
||||
// Merge data lama dengan data baru
|
||||
$existingData = json_decode($inspeksi->data_form, true) ?: [];
|
||||
@@ -33,6 +35,7 @@ class SaveFormInspesksiService
|
||||
'upload_gs'
|
||||
];
|
||||
|
||||
|
||||
foreach ($fotoTypes as $fotoType) {
|
||||
if (isset($existingData[$fotoType])) {
|
||||
$processedData[$fotoType] = $existingData[$fotoType];
|
||||
@@ -57,7 +60,7 @@ class SaveFormInspesksiService
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Gagal menyimpan data',
|
||||
'message' => 'Gagal menyimpan data : '.$e->getMessage(),
|
||||
'error' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
@@ -85,36 +88,31 @@ class SaveFormInspesksiService
|
||||
$hasAssetDescriptionRules = false;
|
||||
$hasFactaData = false;
|
||||
|
||||
|
||||
|
||||
$pisah = array_filter(
|
||||
explode(',', $action),
|
||||
function ($act) use ($allowedActions) {
|
||||
return isset($allowedActions[trim($act)]);
|
||||
}
|
||||
);
|
||||
|
||||
// dd($pisah);
|
||||
$actions = array_map('trim', explode(',', $action));
|
||||
$pisah = array_filter($actions, function($act) use ($allowedActions) {
|
||||
return isset($allowedActions[$act]);
|
||||
});
|
||||
|
||||
foreach ($pisah as $act) {
|
||||
$act = trim($act); // Bersihkan spasi
|
||||
if (isset($allowedActions[$act])) {
|
||||
$method = $allowedActions[$act];
|
||||
if($act){
|
||||
if (isset($allowedActions[$act])) {
|
||||
$method = $allowedActions[$act];
|
||||
|
||||
$actionRules = $this->$method($data, $request, $inspeksi);
|
||||
$rules = array_merge($rules, $actionRules);
|
||||
$actionRules = $this->$method($data, $request, $inspeksi);
|
||||
$rules = array_merge($rules, $actionRules);
|
||||
// Cek apakah act memerlukan asset description rules
|
||||
if($act){
|
||||
if (in_array($act, ['apartemen-kantor', 'tanah', 'bangunan', 'rap'])) {
|
||||
$hasAssetDescriptionRules = true;
|
||||
}
|
||||
|
||||
// Cek apakah act memerlukan asset description rules
|
||||
if (in_array($act, ['apartemen-kantor', 'tanah', 'bangunan', 'rap'])) {
|
||||
$hasAssetDescriptionRules = true;
|
||||
}
|
||||
|
||||
// Cek apakah act memerlukan fakta data
|
||||
if (in_array($act, ['rap'])) {
|
||||
$hasFactaData = true;
|
||||
if (in_array($act, ['rap'])) {
|
||||
$hasFactaData = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($hasAssetDescriptionRules) {
|
||||
@@ -450,8 +448,6 @@ class SaveFormInspesksiService
|
||||
|
||||
$data['perizinan'] = $perizinanData;
|
||||
|
||||
|
||||
|
||||
$partisiResult = [];
|
||||
if (isset($data['partisi'])) {
|
||||
foreach ($data['partisi'] as $name => $values) {
|
||||
|
||||
Reference in New Issue
Block a user