diff --git a/action_delete.go b/action_delete.go index f62e139..4721d45 100644 --- a/action_delete.go +++ b/action_delete.go @@ -2,6 +2,7 @@ package devicemngmt import ( "context" + "errors" "fmt" "github.com/Selly-Modules/logger" @@ -18,6 +19,11 @@ func (s Service) DeleteByDeviceID(deviceID string) error { } ) + total, _ := col.CountDocuments(ctx, cond) + if total == 0 { + return errors.New("deviceId not found") + } + // Delete if _, err := col.DeleteOne(ctx, cond); err != nil { logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{ diff --git a/action_update.go b/action_update.go index f092c65..e4f7b22 100644 --- a/action_update.go +++ b/action_update.go @@ -2,6 +2,7 @@ package devicemngmt import ( "context" + "errors" "fmt" "github.com/Selly-Modules/logger" @@ -30,6 +31,11 @@ func (s Service) UpdateByDeviceID(deviceID string, payload UpdateOptions) error } ) + total, _ := col.CountDocuments(ctx, cond) + if total == 0 { + return errors.New("deviceId not found") + } + // Validate payload err := payload.validate() if err != nil {