Skip to content
Snippets Groups Projects
Commit 3aeaa8ff authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Refactor : factorize code

parent f3892601
No related branches found
No related tags found
1 merge request!42Resolve "Capture votes"
......@@ -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
);
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment