update DeleteByUserID
This commit is contained in:
parent
c67099df03
commit
9435340e44
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Selly-Modules/logger"
|
"github.com/Selly-Modules/logger"
|
||||||
|
"github.com/Selly-Modules/mongodb"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,13 +40,19 @@ func (s Service) DeleteByDeviceID(deviceID string) error {
|
||||||
// DeleteByUserID ...
|
// DeleteByUserID ...
|
||||||
func (s Service) DeleteByUserID(userID string) error {
|
func (s Service) DeleteByUserID(userID string) error {
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
col = s.getDeviceCollection()
|
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
|
// Delete
|
||||||
if _, err := col.DeleteMany(ctx, cond); err != nil {
|
if _, err := col.DeleteMany(ctx, cond); err != nil {
|
||||||
logger.Error("devicemngmt - deleteByUserID", logger.LogData{
|
logger.Error("devicemngmt - deleteByUserID", logger.LogData{
|
||||||
|
|
Loading…
Reference in New Issue