Quellcode durchsuchen

fix: update description by product id

Fernando vor 4 Monaten
Ursprung
Commit
9a11e854c2
2 geänderte Dateien mit 9 neuen und 9 gelöschten Zeilen
  1. 5 3
      controllers/DescriptionUpdateController.php
  2. 4 6
      models/DescriptionModel.php

+ 5 - 3
controllers/DescriptionUpdateController.php

@@ -15,18 +15,20 @@ class DescriptionUpdateController
         $body = json_decode((string) $request->getBody(), true) ?? [];
 
         try {
-            v::key('description_id', v::intType()->positive())
+            v::key('product_id', v::intType()->positive())
+             ->key('company_id', v::intType()->positive())
              ->key('description_text', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
             return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400);
         }
 
-        $descriptionId = (int) $body['description_id'];
+        $productId = (int) $body['product_id'];
+        $companyId = (int) $body['company_id'];
         $descriptionText = (string) $body['description_text'];
 
         $model = new DescriptionModel();
-        $success = $model->updateDescription($descriptionId, $descriptionText);
+        $success = $model->updateDescription($productId, $companyId, $descriptionText);
 
         return $success
             ? ResponseLib::sendOk(['updated' => true])

+ 4 - 6
models/DescriptionModel.php

@@ -27,15 +27,13 @@ class DescriptionModel
         ]);
     }
 
-    public function updateDescription(int $descriptionId, string $text): bool
+    public function updateDescription(int $productId, int $companyId, string $text): bool
     {
-        $stmt = $this->pdo->prepare("
-            UPDATE description SET description_text = :text
-            WHERE description_id = :id
-        ");
+        $stmt = $this->pdo->prepare("UPDATE description SET description_text = :text WHERE product_id = :product_id AND company_id = :company_id");
         return $stmt->execute([
             'text' => $text,
-            'id' => $descriptionId,
+            'product_id' => $productId,
+            'company_id' => $companyId,
         ]);
     }
 }