backend-01

commit 5cf5b2fae1c4978b5d940cb88382d0612ba405a5

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

bill: only set tags and pdf file if was uploaded

 app/controllers/BillsController.php | 20 +++++++++++---------


diff --git a/app/controllers/BillsController.php b/app/controllers/BillsController.php
index 63ef3e74ed6c651e18a57dbd9d4f6496dc5f3f95..13085f99f1faf54bb11981314ec014a5f0283a70 100644
--- a/app/controllers/BillsController.php
+++ b/app/controllers/BillsController.php
@@ -35,16 +35,18 @@   }
 
   public function store() {
     $data = $_POST;
-
     $pdfPath = null;
-    $fileUploadingService = new FileUploadingService();
-    $uploadResult = $fileUploadingService->upload($_FILES['pdf'], 'bill_');
 
-    if ($uploadResult['success']) {
-      $pdfPath = $uploadResult['filePath'];
-    } elseif (isset($uploadResult['error'])) {
-      echo 'Error: ' . $uploadResult['error'];
-      return;
+    if (!empty($data['pdf'])) {
+      $fileUploadingService = new FileUploadingService();
+      $uploadResult = $fileUploadingService->upload($_FILES['pdf'], 'bill_');
+
+      if ($uploadResult['success']) {
+        $pdfPath = $uploadResult['filePath'];
+      } elseif (isset($uploadResult['error'])) {
+        echo 'Error: ' . $uploadResult['error'];
+        return;
+      }
     }
 
     $bill = new Bill(
@@ -58,7 +60,7 @@       [],
       $pdfPath
     );
 
-    $this->billDAO->create($bill, $data['tags']);
+    $this->billDAO->create($bill, $data['tags'] ?? []);
 
     header('Location: /dashboard');
     exit;