Skip to content

Commit

Permalink
Aligned PROD and DEV cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDyze committed Nov 10, 2024
1 parent 1202bf7 commit 5f18aa3
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function createOrder(OrderViewModel $data, int $userId): OrderViewModel
}
else
{
$articleParam = [$item->DVDId, $item->DVDId, 1, 0, $data->Order->Id];
$articleId = $this->insertStatement("INSERT INTO articles (DVDId, Price, OrderQuantity, ReturnedQuantity, OrderId) VALUE (?, (SELECT Price FROM dvds WHERE Id = ?), ?, ?, ?)", $articleParam);
$articleParam = [$item->DVDId, $item->DVDId, $data->Order->Id];
$articleId = $this->insertStatement("INSERT INTO articles (DVDId, Price, OrderId) VALUE (?, (SELECT Price FROM dvds WHERE Id = ?), ?)", $articleParam);
if(!$articleId)
{
throw new CustomException(502, "Impossible de créer l'article");
Expand Down Expand Up @@ -240,7 +240,7 @@ public function addArticle($orderId, $dvdId)
{
$pdo->beginTransaction();

$articleParam = [$dvdId, $dvdId, 1, 0, $orderId];
$articleParam = [$dvdId, $dvdId, $orderId];
$articleId = $this->fetchValue("SELECT Id FROM articles WHERE DVDId = ? AND OrderId = ?", [$dvdId, $orderId]);

// Cannot add the same article twice
Expand All @@ -249,7 +249,7 @@ public function addArticle($orderId, $dvdId)
return;
}

$articleId = $this->insertStatement("INSERT INTO articles (DVDId, Price, OrderQuantity, ReturnedQuantity, OrderId) VALUE (?, (SELECT Price FROM dvds WHERE Id = ?), ?, ?, ?)", $articleParam);
$articleId = $this->insertStatement("INSERT INTO articles (DVDId, Price, OrderId) VALUE (?, (SELECT Price FROM dvds WHERE Id = ?), ?)", $articleParam);
if(!$articleId)
{
throw new CustomException(502, "Impossible de créer l'article");
Expand Down Expand Up @@ -284,9 +284,25 @@ public function cancelOrder($orderId)

public function validateOrder($orderId)
{
if(!$this->executeStatement("UPDATE orders SET StatusId = ? WHERE Id = ?;", [StatusEnum::Ordered->value, $orderId]))

$pdo = $this->getDBContext();
try
{
throw new CustomException(502, "Impossible de supprimer la commande");
$pdo->beginTransaction();

// TODO: Decrement the stock!

if(!$this->executeStatement("UPDATE orders SET StatusId = ? WHERE Id = ?;", [StatusEnum::Ordered->value, $orderId]))
{
throw new CustomException(502, "Impossible de valider la commande");
}

$pdo->commit();
}
catch(Exception $e)
{
$pdo->rollBack();
throw $e;
}
}
}

0 comments on commit 5f18aa3

Please sign in to comment.