update delete action

This commit is contained in:
Hoang 2021-11-23 16:44:42 +07:00
parent 1c4cbb1868
commit d5d0979321
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package devicemngmt
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/Selly-Modules/logger" "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 // Delete
if _, err := col.DeleteOne(ctx, cond); err != nil { if _, err := col.DeleteOne(ctx, cond); err != nil {
logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{ logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{

View File

@ -2,6 +2,7 @@ package devicemngmt
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/Selly-Modules/logger" "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 // Validate payload
err := payload.validate() err := payload.validate()
if err != nil { if err != nil {