add GetUserIDByDeviceId
This commit is contained in:
		
							parent
							
								
									691f9080ab
								
							
						
					
					
						commit
						0feeba0735
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue