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 (
"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{

View File

@ -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 {