Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use linq in nested of nested object #106

Open
renerlemes opened this issue Sep 23, 2023 · 0 comments
Open

How to use linq in nested of nested object #106

renerlemes opened this issue Sep 23, 2023 · 0 comments

Comments

@renerlemes
Copy link

renerlemes commented Sep 23, 2023

I have the following code:

const condominioImovelOriginal = props.data.Condominios.filter((condominio: any) =>
		condominio.Imoveis.find((imovel: any) => imovel.Reservas.find((reserva: any) => reserva.Id == selectedReservation.Reserva.Id))
	).map((condominio: any) => {
		const imovel = condominio.Imoveis.find((imovel: any) => imovel.Reservas.find((reserva: any) => reserva.Id == 46630));

		return {
			Condominio: {
				Id: condominio.Id,
				Nome: condominio.Nome
			},
			Imovel: {
				Id: imovel.Id,
				Nome: imovel.Nome
			},
			Reserva: selectedReservation.Reserva
		};
	})[0];

How to use this lib in this code? I want to filter by Condominios.Imoveis.Reservas.Id === 46630

Condominios (Condominium) = Array
Reservas (Reservations) = Array
Imoveis (Properties) = Array

The JSON:

"Condominios": [
        {
            "Id": 1,
            "Nome": "Fiore Prime",
            "Imoveis": [
                {
                    "Id": 1,
                    "Nome": "A 0301",
                    "Reservas": [
                        {
                            "Id": 46630,
                            "DataCheckIn": "2023-09-23",
                            "DataCheckOut": "2023-09-25",
                            "Diarias": 2,
                            "Cliente": "Rener Lemes",
                            "Status": "Confirmada",
                            "StatusFinanceiro": "EmAberto"
                        },
                        {
                            "Id": 47678,
                            "DataCheckIn": "2023-09-26",
                            "DataCheckOut": "2023-09-29",
                            "Diarias": 3,
                            "Cliente": "Rener Lemes",
                            "Status": "Confirmada",
                            "StatusFinanceiro": "EmAberto"
                        }
                    ]
                },
                {
                    "Id": 252,
                    "Nome": "A 0302",
                    "Reservas": []
                }
            ]
        }
    ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant