add GetUserIDByDeviceId

This commit is contained in:
Hoang 2021-11-26 17:24:14 +07:00
parent 691f9080ab
commit 0feeba0735
1 changed files with 32 additions and 0 deletions

View File

@ -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
}