From c6713f686516611c92da75d5dbf980551370bd1b Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Tue, 7 Oct 2025 23:41:57 +0200 Subject: [PATCH] Return newly added customer note as array in API response - Updated `addNote` in `users_o` to return the `customer_notes_o` object. - Modified `customerNotes` endpoint to include note details in the success response. - Introduced `asArray` method in `customer_notes_o` for structured API responses. --- services/nginx/app/objects/customer_notes_o.php | 11 +++++++++++ services/nginx/app/objects/users_o.php | 3 ++- services/nginx/app/routes/customerNotes.php | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/services/nginx/app/objects/customer_notes_o.php b/services/nginx/app/objects/customer_notes_o.php index 2750c4c4..8566f807 100644 --- a/services/nginx/app/objects/customer_notes_o.php +++ b/services/nginx/app/objects/customer_notes_o.php @@ -125,4 +125,15 @@ class customer_notes_o extends db $customer_id = $this->getCustomerByNoteId($this->id); redis->clear_customer_notes($customer_id); } + + public function asArray(): array + { + return [ + 'id' => $this->id, + 'customer_id' => $this->customer_id->value(), + 'note' => $this->note->value(), + 'cashier_id' => $this->cashier_id->value(), + 'deleted_at' => $this->deleted_at->value(), + ]; + } } \ No newline at end of file diff --git a/services/nginx/app/objects/users_o.php b/services/nginx/app/objects/users_o.php index 5bd55695..7fb57691 100644 --- a/services/nginx/app/objects/users_o.php +++ b/services/nginx/app/objects/users_o.php @@ -389,13 +389,14 @@ class users_o extends db return $customer_notes->getCustomerNotesAsArray($this->id); } - public function addNote($customer_id, $note, $cashier_id): void + public function addNote($customer_id, $note, $cashier_id): customer_notes_o { global $db; // Create the customer notes object $customer_notes = new customer_notes_o(); // Add the note $customer_notes->add($customer_id, $note, $cashier_id); + return $customer_notes; } public function deleteNote(int $note_id): void diff --git a/services/nginx/app/routes/customerNotes.php b/services/nginx/app/routes/customerNotes.php index b64dd1be..20b34807 100644 --- a/services/nginx/app/routes/customerNotes.php +++ b/services/nginx/app/routes/customerNotes.php @@ -74,11 +74,11 @@ class customerNotes if (!$customer->exists()) { $response->error('Customer not found', 400); } - $customer->addNote((int)$customer->id, (string)$data['note'], (int)$user->id); + $note = $customer->addNote((int)$customer->id, (string)$data['note'], (int)$user->id); // Log the incident (new logs_o())->add('customer_notes', 'global', 1, $user->id, 'ADD_CUSTOMER_NOTE', 'Successfully added a customer note'); // Return a success message - $response->success(['message' => 'Customer note added']); + $response->success($note->asArray()); } else { // Log the incident (new logs_o())->add('customer_notes', 'global', 1, 0, 'ADD_CUSTOMER_NOTE', 'No user found, or invalid session');