This endpoint deletes a product identified by its UUID. The deletion will fail if there are existing sales that reference this product due to foreign key constraints.
Path Parameters
Product UUID identifierValidation: Must be a valid UUID format
Response
Indicates if an error occurred during the request
Response message describing the result
Success Response Example (200)
{
"error": false,
"msg": "Product deleted successfully"
}
Error Responses
400 - Invalid UUID
{
"error": true,
"msg": "the id is invalid"
}
409 - Foreign Key Constraint Violation
A product cannot be deleted if it is referenced in any sales. You must delete or update the related sales first.
When attempting to delete a product that has associated sales, the API returns a list of all sales (sale details and sale IDs) that reference this product:
{
"error": true,
"msg": "there are sales with this product",
"salesList": [
{
"idSaleDetails": "4033e9a1-5858-44c9-b1d7-39c718933372",
"idSale": "878d89a7-a1a1-4411-a359-1ad08965fb30"
}
]
}
Array of sales that reference this product (only present when deletion fails)
Database Constraints
The product has foreign key relationships with:
- Sales Details: Products referenced in sales cannot be deleted
- Categories: Products must belong to a valid category
Before deleting a product, ensure:
- No sales contain this product, or
- Remove the product from all sales first, or
- Delete the sales that contain this product