add deleteByUserID

This commit is contained in:
Hoang 2021-11-24 15:36:24 +07:00
parent d5d0979321
commit bff00bfa84
1 changed files with 22 additions and 0 deletions

View File

@ -35,3 +35,25 @@ func (s Service) DeleteByDeviceID(deviceID string) error {
return nil
}
// DeleteByUserID ...
func (s Service) DeleteByUserID(userID string) error {
var (
ctx = context.Background()
col = s.getDeviceCollection()
cond = bson.M{
"userId": userID,
}
)
// Delete
if _, err := col.DeleteMany(ctx, cond); err != nil {
logger.Error("devicemngmt - deleteByUserID", logger.LogData{
"userId": userID,
"err": err.Error(),
})
return fmt.Errorf("error when delete device by userId: %s", err.Error())
}
return nil
}