Ways to retrieve information from a specific key

I'm currently facing a challenge accessing specific data objects that are referenced by keys. In this particular scenario, the "applicant" data is nested within an Event object. My goal is to extract this data and create a new object from it. While I can easily access the top-level Event data and the keys for each applicant, I'm struggling to retrieve additional details such as application date, notes, and status.

My attempted approach of using something like applicationStatus = key.status has not been successful.

onCreateApplication () {
  fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
  let appsArray = []

  querySnapshot.forEach(doc => {
    let event = doc.data()
    let eventId = doc.data().id
    let eventTitle = doc.data().title
    let eventSlug = doc.data().slug
    let applications = doc.data().applicants
    
    // Unable to access applicant data directly
    let appStatus = doc.data().applicants.status
    
    for (var key in doc.data().applicants) {
      let eventData = {
        id: eventId,
        title: eventTitle,
        slug: eventSlug
      }
      let userData = {
        id: key
      }
      
      // Unsure how to accurately access status and appliedDate
      let application = {
        event: eventData,
        user: userData,
        status: key.status????????,
        appliedDate: key.created??????
      }
      fb.applicationsCollection.add(application)
    }

  })

  })
},

Answer №1

After looking into your data structure, I have formulated my best guess on what may be going wrong. If you need further clarification, feel free to leave a comment.

onCreateApplication(){
  fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
    querySnapshot.forEach(doc => {
      let data = doc.data();    
      let applications = Object.keys(data.applicants).map(function(id){
        let application = {
          event: {
            id: data.id,
            title: data.title,
            slug: data.slug
          },
          user: {
            id: id
          },
          status: data.applicants[id].status,
          appliedDate: data.applicants[id].created
        })

        fb.applicationsCollection.add(application);

        return application;
      })
    })
  })
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Add small pieces of content to CKEditor

Is there a way to add "atomic" block content into CKEditor? For instance, I would like to add <h1>Test</h1> right after the letter "B" in the sentence <p>A B C</p>. Currently, when using CKEDITOR.currentInstance.insertHtml('&l ...

Provide net.socket as a parameter

What is the best way to pass the net.socket class as an argument in this scenario? Here's my code snippet: this.server = net.createServer(this.onAccept.bind(this)); this.server.listen(this.port); } Server.prototype.onAccept = function () { // Ho ...

Connects URLs to the displayed outcomes in jQuery Auto-suggest Interface

This particular code snippet has been modified from a tutorial on jQuery autocomplete <!doctype html> <html lang="en> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> ...

Does AngularJS have a feature similar to jQuery.active?

As I utilize selenium to conduct tests on my application, I am encountering numerous ajax calls that utilize $resource or $http. It would be convenient if there was a method in angular to monitor active ajax requests so that selenium could wait until they ...

Ways to verify the contents of an NPM package

After successfully installing the npm package @mediapipe/camera_utils, I am now curious about how to explore the contents within it. Can someone guide me on how to achieve this? ...

The flow of Ajax execution halts once the initial calculation is completed

I have been developing an AJAX code that calculates fees. The code works well initially, but it stops functioning when I try to perform a second operation. <script> var weight = document.getElementById("weight").value; var ship_type = document.g ...

How to trigger a JavaScript function using a button click

I've been struggling to figure out why my JavaScript code isn't functioning properly within Ionic. Can anyone guide me on how to store a number in a variable, display that variable, and increment it when a button is clicked? I have successfully ...

Choose all elements by their class except for a particular container defined by the parent element's ID

Can you provide an example of translating the function below into utilizing the .not method (or not selector)? $(".CLASS").filter(function(i, e){ return (e.parentNode.id != "ID"); } ...

Tips for resolving the issue: Uncaught (in promise) SyntaxError: Unexpected end of input in Fetch API

When I click the button, I am executing this function. Despite adding a header in my API, an error is still being displayed. Here is the code snippet for the function: let getData = () => { console.log("getData function started"); ...

Tips for retrieving the values of both a checkbox and radio button in AngularJS

Hello, I have created MY PLUNKER I have a condition in my JSON where if the minimum value of the ingredients is equal to one, it will change to a radio button. If it's greater than one, it will change to a checkbox. To display as a radio button: ng ...

Forwarding requests via middleware in next.js 13 AppDir: true

I am currently working on implementing a redirect feature in next.js 13 when the jwt back-end is not received. This is being done with the appdir activated. This is the code in my middleware.ts file: import { NextResponse } from 'next/server' im ...

How to Use JQuery to Retrieve the Nearest TD Element's Text Content

Hey there, here is some HTML code that I need help with: <tbody> <tr> <td class="text-center"><input type="text" class="form-control cardSerialNumber"></td> <td class="text-center"><button type="button" onc ...

End your Idp session and log out using passport-saml

Encountering a 400 bad request error when attempting to log out a user from the idp session. Despite successfully logging out the user from the application/passport session, they remain logged in to the idp session. The logout and callback endpoints are c ...

Ways to retrieve a converted document using the Microsoft Graph API

I'm encountering an issue when trying to save a PDF file received from the Microsoft Graph API. The call I am making looks like this: const convertConfig = { headers: { Authorization: <my token> } }; convertConfig.headers['C ...

Protractor Cucumber: Issue with locating spec file patterns (identifying 2 features)

I am facing an issue with running 2 different cucumber features. After adding the following lines to my protractor.conf.js file: specs: ['add.feature', 'delete.feature'] I encountered a problem when running the tests stating pattern ...

When using React.js Material UI's CardActionArea with a flex display, the children elements may not automatically use the full width as expected

Getting straight to the point - I recently experimented with changing the display style property from block to flex, along with setting flexDirection: 'column' for the CardActionArea component. The main goal was to ensure that CardContent maintai ...

The Discord.js error message popped up, stating that it was unable to access the property 'then' since it was undefined

I'm currently working on implementing a mute command for my discord bot, but I'm encountering an error that says; TypeError: Cannot read property 'then' of undefined I am unsure of what is causing this issue and would greatly apprecia ...

"Integrating multiple partials with templateUrl in AngularJS: A step-by-step

Is there a way to merge partial views using the templateUrl attribute in an AngularJS directive? Imagine having a directive like this: .directive('combinePartials', function () { var mainPartial = "mainpartial.html", var template2 = "pa ...

Defining the flow and functionality

I'm currently attempting to define a function signature using Flow. I had anticipated that the code below would generate an error, but surprisingly, no errors are being thrown. What could be causing this issue? // This function applies another functi ...

Requesting data with Ajax: utilizing parameters in the format of x-www-form-urlencoded

When adding parameters to a get/post request, it is important to encode them in application/x-www-form-urlencoded form. Is it necessary to encode values each time? Does JavaScript provide a method for encoding values? What options are available for caching ...