Untitled
unknown
javascript
2 years ago
1.4 kB
1
Indexable
Never
useEffect(() => { const getContacts = async() => { // Query instances const Contacts = Moralis.Object.extend("Contacts"); const Addresses = Moralis.Object.extend("Addresses"); const queryContacts = new Moralis.Query(Contacts); const queryAddress = new Moralis.Query(Addresses); // Setting logged in user const user = Moralis.User.current(); // Contacts query which our user is the owner of // Pointer set to (respective) _User on DB queryContacts.equalTo('owner', user); const contactResults = await queryContacts.find(); // Addresses query which individual contacs are the owner of // Pointer set to (respective) Contact on DB queryAddress.select('address', 'network', 'notes'); const addressResults = await queryAddress.find(); let results =[] if (contactResults) { for (let i = 0; i < addressResults.length; i++); for (let i = 0; i < contactResults.length; i++) results.push({ name: contactResults[i].attributes?.name, contactCards: { address: addressResults[i].attributes?.address, network: addressResults[i].attributes?.network, notes: addressResults[i].attributes?.notes, } }) console.log(results) } } return () => { getContacts() } }, [])