update DeleteByUserID

This commit is contained in:
Hoang 2022-02-22 16:36:26 +07:00
parent c67099df03
commit 9435340e44
1 changed files with 12 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"github.com/Selly-Modules/logger"
"github.com/Selly-Modules/mongodb"
"go.mongodb.org/mongo-driver/bson"
)
@ -41,11 +42,17 @@ func (s Service) DeleteByUserID(userID string) error {
var (
ctx = context.Background()
col = s.getDeviceCollection()
cond = bson.M{
"userId": userID,
}
)
id, isValid := mongodb.NewIDFromString(userID)
if !isValid {
return errors.New("invalid userID data")
}
cond := bson.M{
"userId": id,
}
// Delete
if _, err := col.DeleteMany(ctx, cond); err != nil {
logger.Error("devicemngmt - deleteByUserID", logger.LogData{