// ValidateRoles check if provided roles exist in roles collection
ValidateRoles check if provided roles exist in roles collection
// ValidateRoles check if provided roles exist in roles collection
func (this *UserRepository) ValidateRoles(roles []*models.Role) error {
	queue := make(chan RoleResult, len(roles))
	for _, role := range roles {
		rr := RoleResult{
			Role:  role.Role,
			Level: role.Level,
		}
		rr.Result = this.roles.FindOne(
			context.Background(),
			bson.NewDocument(
				bson.EC.String("role", role.Role),
				bson.EC.Int32("level", int32(role.Level)),
			))
		queue <- rr
	}
	close(queue)
	for elem := range queue {
		var result interface{}
		err := elem.Result.Decode(result)
		if err != nil {
			return errors.New("Role: " + elem.Role + " with Level: " + strconv.Itoa(int(elem.Level)) + " does not exist. ")
		}
	}
	return nil
}
func ( this * UserRepository ) ValidateRoles ( roles [ ] * models . Role ) error { queue := make ( chan RoleResult , len ( roles ) ) for _ , role := range roles { rr := RoleResult { Role : role . Role , Level : role . Level , } rr . Result = this . roles . FindOne ( context . Background ( ) , bson . NewDocument ( bson . EC . String ( " " , role . Role ) , bson . EC . Int32 ( " " , int32 ( role . Level ) ) , ) ) queue <- rr } close ( queue ) for elem := range queue { var result interface { } err := elem . Result . Decode ( result ) if err != nil { return errors . New ( " " + elem . Role + " " + strconv . Itoa ( int ( elem . Level ) ) + " " ) } } return nil }
ValidateRoles check if provided roles exist in roles collection
ValidateRoles check if provided roles exist in roles collection