Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public/error_log
# /tests/e2e-backup
playwright-report/
test-results/
mcp.json
/build
mcp.json
5 changes: 5 additions & 0 deletions app/Models/Agama.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Agama extends Model
{
use HasFactory;

public $timestamps = false;

protected $table = 'ref_agama';

protected $fillable = ['nama'];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Cacat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Cacat extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_cacat';

protected $fillable = ['nama'];
Expand Down
5 changes: 4 additions & 1 deletion app/Models/DataDesa.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ public function pembangunan()
return $this->hasMany(Pembangunan::class, 'desa_id', 'desa_id');
}

/**
* Alias accessor/mutator for kode_desa to map to desa_id.
*/
public function getKodeDesaAttribute()
{
return $this->desa_id;
}
}
}
2 changes: 2 additions & 0 deletions app/Models/DataUmum.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class DataUmum extends Model
{
use HasFactory;
// Attributes
protected $table = 'das_data_umum';

Expand Down
4 changes: 4 additions & 0 deletions app/Models/GolonganDarah.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class GolonganDarah extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_golongan_darah';

protected $fillable = ['nama'];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/HubunganKeluarga.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class HubunganKeluarga extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_hubungan_keluarga';

protected $fillable = ['nama'];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Kawin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Kawin extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_kawin';

protected $fillable = ['nama'];
Expand Down
2 changes: 2 additions & 0 deletions app/Models/OtpToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class OtpToken extends Model
{
use HasFactory;
/**
* {@inheritDoc}
*/
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Pekerjaan.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Pekerjaan extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_pekerjaan';

protected $fillable = ['nama'];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Pendidikan.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Pendidikan extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_pendidikan';

protected $fillable = ['nama'];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/PendidikanKK.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class PendidikanKK extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_pendidikan_kk';

protected $fillable = ['nama'];
Expand Down
10 changes: 10 additions & 0 deletions app/Models/PendidikanKk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class PendidikanKk extends PendidikanKK
{
use HasFactory;
}
1 change: 0 additions & 1 deletion app/Models/Penduduk.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public function keluarga()
{
return $this->hasOne(Keluarga::class, 'no_kk', 'no_kk');
}

public function suplemen_terdata()
{
return $this->hasMany(SuplemenTerdata::class, 'penduduk_id', 'id');
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Profil.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Cache;

class Profil extends Model
{
use HasFactory;
// ID Kecamatan untuk default profil

protected $table = 'das_profil';
Expand Down
7 changes: 6 additions & 1 deletion app/Models/SettingAplikasi.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ class SettingAplikasi extends Model
{
use HasFactory;
protected $table = 'das_setting';

protected $fillable = [
'key',
'value',
'type',
'description',
'option',
'kategori',
];

public $timestamps = false;
Expand Down
11 changes: 10 additions & 1 deletion app/Models/Warganegara.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Warganegara extends Model
{
use HasFactory;

public $timestamps = false;
protected $table = 'ref_warganegara';

protected $fillable = ['nama'];

public function penduduk()
{
return $this->hasMany(Penduduk::class);
}
}
16 changes: 12 additions & 4 deletions app/Services/BaseApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\SettingAplikasi;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;

class BaseApiService
Expand Down Expand Up @@ -36,15 +37,22 @@ protected function apiRequest(string $endpoint, array $params = [])
// Buat permintaan API dengan Header dan Parameter
$response = Http::withHeaders($this->header)->get($this->baseUrl . $endpoint, $params);
session()->forget('error_api');
$jsonResponse = $response->json();

if($this->isFullResponse()) {
// Jika full response, kembalikan seluruh response
return $response->json();
return $jsonResponse;
}
// Return JSON hasil
return $response->json('data') ?? [];

// Return JSON hasil, cek apakah ada key 'data', jika tidak ada kembalikan seluruh response
if (isset($jsonResponse['data'])) {
return $jsonResponse['data'];
}

return $jsonResponse;
} catch (\Exception $e) {
session()->flash('error_api', 'Gagal mendapatkan data'. $e->getMessage());
\Log::error('Failed get data in '.__FILE__.' function '.__METHOD__.' '. $e->getMessage());
Log::error('Failed get data in '.__FILE__.' function '.__METHOD__.' '. $e->getMessage());
}
return [];
}
Expand Down
28 changes: 20 additions & 8 deletions app/Services/FileUploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,24 @@ protected function sanitizeDirectoryPath(string $directory): string
*/
protected function sanitizeExtension(string $extension): string
{
// Only allow alphanumeric characters and a few safe characters in extension
$sanitized = preg_replace('/[^a-zA-Z0-9]/', '', $extension);

// Return sanitized extension or empty string if invalid
return ctype_alnum($sanitized) ? $sanitized : 'tmp';
// Normalize and lower case
$ext = strtolower($extension);

// If extension contains php anywhere, treat as unsafe
if (strpos($ext, 'php') !== false) {
return 'tmp';
}

// Block known executable / script extensions
$blacklist = ['php', 'php3', 'php4', 'php5', 'phtml', 'exe', 'sh', 'bat', 'pl', 'py'];
if (in_array($ext, $blacklist, true)) {
return 'tmp';
}

// Only allow alphanumeric characters in extension
$sanitized = preg_replace('/[^a-zA-Z0-9]/', '', $ext);

return $sanitized !== '' ? $sanitized : 'tmp';
}

/**
Expand All @@ -133,9 +146,8 @@ protected function generateSafeFileName(UploadedFile $file): string
{
// Get original name and sanitize it to prevent path traversal
$originalName = $file->getClientOriginalName();

// Check if original name contains path traversal characters
if (str_contains($originalName, '../') || str_contains($originalName, '..\\')) {
// Reject if original name contains traversal or contains directory parts
if (str_contains($originalName, '..') || basename($originalName) !== $originalName || preg_match('/[\\\\\/]/', $originalName)) {
throw new \InvalidArgumentException("File name contains path traversal attempts");
}

Expand Down
29 changes: 25 additions & 4 deletions app/Services/KeluargaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function keluarga(int $id)
// Panggil API dan ambil data
$data = $this->apiRequest('/api/v1/keluarga', $params);

// Handle empty response
if (empty($data)) {
throw new \Exception('Keluarga data not found');
}

$result = collect($data)
->map(function ($item) {
return (object) [
Expand All @@ -37,7 +42,12 @@ public function keluarga(int $id)
];
});

return $result[0];
// Check if result has items
if ($result->isEmpty()) {
throw new \Exception('Keluarga data not found');
}

return $result->first();
}

/**
Expand Down Expand Up @@ -70,28 +80,39 @@ public function exportKeluarga(array $params = [], $all = false)
// Default parameter
$defaultParams = [
'filter[kode_kecamatan]' => str_replace('.', '', config('profil.kecamatan_id')),
'filter[kode_desa]' => request()->desa,
'all' => $all
];

// Only add desa filter if it exists in the request
if (request()->has('desa')) {
$defaultParams['filter[kode_desa]'] = request()->desa;
}

// Gabungkan parameter default dengan filter dinamis
$finalParams = array_merge($defaultParams, $params);

// Panggil API dan ambil data
$data = $this->apiRequest('/api/v1/keluarga', $finalParams);

// Handle empty response
if (empty($data)) {
return collect([]);
}

// Format ulang data jika diperlukan
return collect($data)->map(function ($item) {
return (object) [
'id' => $item['id'],
'nik_kepala' => $item['attributes']['nik_kepala'] ?? '',
'kepala_kk' => (object) ['nama' => $item['attributes']['nama_kk'] ?? ''],
'kepala_kk_nama' => $item['attributes']['nama_kk'] ?? '', // Changed from kepala_kk object to kepala_kk_nama string
'kepala_kk' => (object) ['nama' => $item['attributes']['nama_kk'] ?? ''], // Keep for backward compatibility
'no_kk' => $item['attributes']['no_kk'] ?? '',
'alamat' => $item['attributes']['alamat'] ?? '',
'dusun' => $item['attributes']['dusun'] ?? '',
'rw' => $item['attributes']['rw'] ?? '',
'rt' => $item['attributes']['rt'] ?? '',
'desa' => (object) ['nama' => $item['attributes']['desa'] ?? ''],
'desa_nama' => $item['attributes']['desa'] ?? '', // Added desa_nama property
'desa' => (object) ['nama' => $item['attributes']['desa'] ?? ''], // Keep for backward compatibility
'tgl_daftar' => $item['attributes']['tgl_daftar'] ?? null,
'tgl_cetak_kk' => (isset($item['attributes']['tgl_cetak_kk']) && $item['attributes']['tgl_cetak_kk'] !== '-') ? $item['attributes']['tgl_cetak_kk'] : null,
'created_at' => null,
Expand Down
7 changes: 4 additions & 3 deletions app/Services/PendudukService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function exportPenduduk($size, $number, $search)
return [
'ID' => $item['id'],
'nama' => $item['attributes']['nama'] ?? '',
'nik' => '`' . $item['attributes']['nik'],
'no_kk' => '`' .$item['attributes']['keluarga']['no_kk'] ?? '',
'nik' => $item['attributes']['nik'] ?? '',
'no_kk' => $item['attributes']['keluarga']['no_kk'] ?? '',
'nama_desa' => $item['attributes']['config']['nama_desa'] ?? '',
'alamat' => $item['attributes']['alamat_sekarang'] ?? '',
'pendidikan' => $item['attributes']['pendidikan_k_k']['nama'] ?? '',
Expand All @@ -109,7 +109,8 @@ public function cekPendudukNikTanggalLahir($nik, $tgl_lhr = null)
]);

if ($response->successful() && $response->json('data')) {
return new Penduduk($response->json('data'));
$pendudukData = $response->json('data');
return new Penduduk($pendudukData);
}

return null;
Expand Down
2 changes: 0 additions & 2 deletions build/report.junit.xml

This file was deleted.

Empty file removed build/teamcity.txt
Empty file.
Loading