diff --git a/pkg/datastore/gormstore/mapfixes.go b/pkg/datastore/gormstore/mapfixes.go index 50f4a05..ee4f0ad 100644 --- a/pkg/datastore/gormstore/mapfixes.go +++ b/pkg/datastore/gormstore/mapfixes.go @@ -55,11 +55,16 @@ func (env *Mapfixes) Update(ctx context.Context, id int64, values datastore.Opti // the update can only occur if the status matches one of the provided values. func (env *Mapfixes) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.MapfixStatus, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil { - if err == gorm.ErrRecordNotFound { + result := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()) + if result.Error != nil { + if result.Error == gorm.ErrRecordNotFound { return datastore.ErrNotExist } - return err + return result.Error + } + + if result.RowsAffected == 0 { + return datastore.ErroNoRowsAffected } return nil diff --git a/pkg/datastore/gormstore/submissions.go b/pkg/datastore/gormstore/submissions.go index 5791819..9f4d149 100644 --- a/pkg/datastore/gormstore/submissions.go +++ b/pkg/datastore/gormstore/submissions.go @@ -55,11 +55,16 @@ func (env *Submissions) Update(ctx context.Context, id int64, values datastore.O // the update can only occur if the status matches one of the provided values. func (env *Submissions) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.SubmissionStatus, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil { - if err == gorm.ErrRecordNotFound { + result := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()) + if result.Error != nil { + if result.Error == gorm.ErrRecordNotFound { return datastore.ErrNotExist } - return err + return result.Error + } + + if result.RowsAffected == 0 { + return datastore.ErroNoRowsAffected } return nil