devicemngmt/action_get_user_id.go

65 lines
1.2 KiB
Go
Raw Normal View History

2021-11-05 10:36:30 +00:00
package devicemngmt
import (
"context"
"github.com/Selly-Modules/logger"
"go.mongodb.org/mongo-driver/bson"
)
// GetUserIDByAuthToken ...
func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
var (
ctx = context.Background()
col = s.getDeviceCollection()
device = Device{}
cond = bson.M{
"authToken": authToken,
}
)
2021-11-26 10:24:14 +00:00
if authToken == "" {
return
}
2021-11-05 10:36:30 +00:00
// Find
if err := col.FindOne(ctx, cond).Decode(&device); err != nil {
2021-11-10 10:08:39 +00:00
logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{
2021-11-05 10:36:30 +00:00
"authToken": authToken,
"err": err.Error(),
})
return
}
2021-11-22 08:14:36 +00:00
userID = device.UserID.Hex()
2021-11-05 10:36:30 +00:00
return
}
2021-11-26 10:24:14 +00:00
// 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
}