diff --git a/action_get_user_id.go b/action_get_user_id.go index 42930bc..20086f9 100644 --- a/action_get_user_id.go +++ b/action_get_user_id.go @@ -18,6 +18,10 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) { } ) + if authToken == "" { + return + } + // Find if err := col.FindOne(ctx, cond).Decode(&device); err != nil { logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{ @@ -30,3 +34,31 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) { userID = device.UserID.Hex() return } + +// GetUserIDByDeviceId ... +func (s Service) GetUserIDByDeviceId(deviceId string) (userID string) { + var ( + ctx = context.Background() + col = s.getDeviceCollection() + device = Device{} + cond = bson.M{ + "deviceId": deviceId, + } + ) + + if deviceId == "" { + return + } + + // Find + if err := col.FindOne(ctx, cond).Decode(&device); err != nil { + logger.Error("devicemngmt - getUserIDByDeviceId", logger.LogData{ + "deviceId": deviceId, + "err": err.Error(), + }) + return + } + + userID = device.UserID.Hex() + return +}