retrieveVotes()

in public/js/components/CommonsDivisions/CommonsDivision.js [50:88]


  retrieveVotes(id) {
    this.setState(Object.assign({}, this.state, {
      status: StatusTypes.RETRIEVE_VOTES
    }));

    //Add the votes to the division then create an atom
    commonsDivision(id).then(data => {
      const raw = data.result.primaryTopic;
      const parliamentId = raw["_about"].split("/").pop();

      const division = {
        parliamentId: parliamentId,
        date: raw.date["_value"],
        title: raw.title,
        votes: {
          ayes: [],
          noes: []
        }
      };

      raw.vote.forEach(vote => {
        const type = vote.type.split("#").pop();
        const mp = {
          name: vote.memberPrinted["_value"],
          party: this.cleanPartyName(vote.memberParty)
        };

        if (type === "AyeVote") this.insertMP(mp, division.votes.ayes, 0, division.votes.ayes.length-1);
        else if (type === "NoVote") this.insertMP(mp, division.votes.noes, 0, division.votes.noes.length-1);
      });

      this.setState(Object.assign({}, this.state, {
        division: division,
        status: StatusTypes.CREATE
      }));

      this.createAtom();
    });
  }