variants as a single product

This commit is contained in:
2026-09-03 10:43:05 +05:30
parent 2401158190
commit da0e9d987e
7 changed files with 205 additions and 4 deletions

View File

@@ -80,6 +80,25 @@ func (r *stockRequestRepository) GetStockRequestByID(requestID int) (*models.Sto
return &req, err
}
// UpdateStockRequest sets one request’s status, and refuses an id that is not
// there.
//
// An UPDATE that matches no row is not an SQL error, so this used to report
// success for a request that does not exist. Approving happened to catch it —
// the service reads the row first to move the stock — but rejecting went
// straight to the UPDATE and said it had worked.
//
// Harmless for one id typed by hand; not harmless in a batch, where the answer
// is a count. Measured on production 2026-09-02: rejecting [31,32,33,9999999]
// answered "4 updated" when only three requests existed. A merchant clearing a
// stale queue would be told every row was dealt with.
func (r *stockRequestRepository) UpdateStockRequest(requestID int, status string) error {
return r.db.Model(&models.StockRequest{}).Where("requestid = ?", requestID).Update("status", status).Error
result := r.db.Model(&models.StockRequest{}).Where("requestid = ?", requestID).Update("status", status)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return gorm.ErrRecordNotFound
}
return nil
}