Implement resubmit rejected data feature for surveyors

This commit is contained in:
cygouw
2026-06-12 16:12:46 +07:00
parent d25df07984
commit f379de42e0
3 changed files with 50 additions and 11 deletions
+10 -2
View File
@@ -108,12 +108,12 @@ if ($method === 'PUT') {
$oldData = $old->fetch();
if (!$oldData) jsonResponse(['success'=>false,'error'=>'Tidak ditemukan'], 404);
// Surveyor hanya bisa edit milik sendiri yang masih pending
// Surveyor hanya bisa edit milik sendiri yang masih pending atau rejected
if ($user['role'] === 'surveyor') {
if ((int)$oldData['surveyor_id'] !== $user['id']) {
jsonResponse(['success'=>false,'error'=>'Anda hanya bisa edit data milik Anda'], 403);
}
if ($oldData['status'] !== 'pending') {
if ($oldData['status'] !== 'pending' && $oldData['status'] !== 'rejected') {
jsonResponse(['success'=>false,'error'=>'Data yang sudah diverifikasi tidak bisa diedit'], 403);
}
}
@@ -131,6 +131,14 @@ if ($method === 'PUT') {
$vals[] = in_array($f,['lat','lng']) ? (float)$body[$f] : ($f==='radius' ? (int)$body[$f] : $body[$f]);
}
}
if ($user['role'] === 'surveyor') {
$fields[] = "status = ?";
$vals[] = 'pending';
$fields[] = "alasan_penolakan = ?";
$vals[] = null;
}
if (empty($fields)) jsonResponse(['success'=>false,'error'=>'Tidak ada data diubah'], 422);
$vals[] = $id;
$db->prepare("UPDATE rumah_ibadah SET ".implode(',',$fields)." WHERE id = ?")->execute($vals);