diff --git a/web/components/vote/votes.js b/web/components/vote/votes.js index 90cfca98ae91feb5b297a0367d4299ee98959587..892686132ec740e9d7dd1e6dea7839d97a8cbf20 100644 --- a/web/components/vote/votes.js +++ b/web/components/vote/votes.js @@ -155,17 +155,8 @@ class Vote { </div> `; let voteHandler = this; - let votes = await this.VoteModel.getVotes(); - votes = votes.filter((vote) => { - return vote.DeskRoundID == voteHandler.DeskRoundID; - }); - let candidateLists = await this.CandidateListModel.getCandidateLists(); - candidateLists = candidateLists.filter((candidateList) => { - return ( - candidateList.AreaID == voteHandler.AreaID && - candidateList.RoundID == voteHandler.RoundID - ); - }); + let votes = await this.updatesVotes(); + let candidateLists = await this.updateCandidateLists(); const markup = candidateLists .map((vote) => this.voteTemplate(vote)) @@ -206,18 +197,8 @@ class Vote { async saveVotes() { let voteHandler = this; - let candidateLists = await this.CandidateListModel.getCandidateLists(); - candidateLists = candidateLists.filter((candidateList) => { - return ( - candidateList.AreaID == voteHandler.AreaID && - candidateList.RoundID == voteHandler.RoundID - ); - }); - - let votes = await this.VoteModel.getVotes(); - votes = votes.filter((vote) => { - return vote.DeskRoundID == voteHandler.DeskRoundID; - }); + let candidateLists = await this.updateCandidateLists(); + let votes = await this.updatesVotes(); let method; if (votes.length == 0) method = "POST"; @@ -255,4 +236,21 @@ class Vote { await this.VoteModel.refreshVotes(); await this.loadVotes(); } + + async updatesVotes() { + let votes = await this.VoteModel.getVotes(); + return votes.filter((vote) => { + return vote.DeskRoundID == voteHandler.DeskRoundID; + }); + } + + async updateCandidateLists() { + let canddiateLists = await this.CandidateListModel.getCandidateLists(); + return candidateLists.filter((candidateList) => { + return ( + candidateList.AreaID == voteHandler.AreaID && + candidateList.RoundID == voteHandler.RoundID + ); + }); + } }