chore: build
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"slices"
|
||||
@@ -348,6 +349,12 @@ func (d *Database) CancelCommandByAdminAtomic(commandID int) error {
|
||||
return fmt.Errorf("commande non trouvée")
|
||||
}
|
||||
prevStatus := cmd.Status
|
||||
if prevStatus == "cancelled" {
|
||||
return nil
|
||||
}
|
||||
if prevStatus == "approved" {
|
||||
return ErrCommandLocked
|
||||
}
|
||||
|
||||
noRestoreStatuses := []string{"cancelled", "approved", "livre"}
|
||||
if !slices.Contains(noRestoreStatuses, prevStatus) {
|
||||
@@ -395,6 +402,9 @@ func (d *Database) CancelDeliveryByLivreurAtomic(commandID int) (alreadyCancelle
|
||||
alreadyCancelled = true
|
||||
return nil
|
||||
}
|
||||
if prevStatus == "livre" || prevStatus == "approved" {
|
||||
return ErrCommandAlreadyDelivered
|
||||
}
|
||||
|
||||
result := tx.Exec(`
|
||||
UPDATE commandes SET status = 'cancelled', updated_at = CURRENT_TIMESTAMP
|
||||
@@ -428,3 +438,5 @@ func (d *Database) CancelDeliveryByLivreurAtomic(commandID int) (alreadyCancelle
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var ErrCommandAlreadyDelivered = errors.New("commande déjà livrée : annulation impossible")
|
||||
|
||||
Reference in New Issue
Block a user