From 5aebc255e875c9196f3277ac53a3cf757507fbeb Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Fri, 17 Apr 2026 10:07:33 +0700 Subject: [PATCH] fix: improve contact detail update errors Surface specific validation and database failures when updating contact details so API responses are actionable. --- .codex | 0 app/Models/Contact/ContactDetailModel.php | 13 ++++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) delete mode 100644 .codex diff --git a/.codex b/.codex deleted file mode 100644 index e69de29..0000000 diff --git a/app/Models/Contact/ContactDetailModel.php b/app/Models/Contact/ContactDetailModel.php index cd5130d..e7e6814 100755 --- a/app/Models/Contact/ContactDetailModel.php +++ b/app/Models/Contact/ContactDetailModel.php @@ -67,7 +67,7 @@ class ContactDetailModel extends BaseModel { { try { if (!empty($operations['edited']) && !$this->updateDetails($contactID, $operations['edited'])) { - return ['status' => 'error', 'message' => 'Failed to update contact details']; + return ['status' => 'error', 'message' => $this->lastDetailError ?? 'Failed to update contact details']; } if (!empty($operations['deleted']) && !$this->softDeleteDetails($contactID, $operations['deleted'])) { @@ -108,6 +108,7 @@ class ContactDetailModel extends BaseModel { foreach ($items as $detail) { $detailID = $detail['ContactDetID'] ?? null; if (!$detailID || !ctype_digit((string) $detailID)) { + $this->lastDetailError = 'ContactDetID is required and must be an integer.'; return false; } @@ -117,6 +118,7 @@ class ContactDetailModel extends BaseModel { ->first(); if (empty($existing)) { + $this->lastDetailError = "Detail record {$detailID} not found for Contact {$contactID}."; return false; } @@ -124,6 +126,13 @@ class ContactDetailModel extends BaseModel { unset($updateData['ContactID']); if ($updateData !== [] && !$this->update((int) $detailID, $updateData)) { + $dbError = $this->db->error(); + $this->lastDetailError = sprintf( + 'Failed to update detail %d for Contact %d%s', + (int) $detailID, + $contactID, + !empty($dbError['message']) ? ': ' . $dbError['message'] : '' + ); return false; } } @@ -131,6 +140,8 @@ class ContactDetailModel extends BaseModel { return true; } + private ?string $lastDetailError = null; + private function softDeleteDetails(int $contactID, array $ids): bool { $ids = array_values(array_unique(array_map('intval', $ids)));