Skip to content

Commit

Permalink
Another fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsanmasdar committed Oct 21, 2018
1 parent 34af0eb commit 843af35
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions server/routes/templates.ts
Expand Up @@ -805,35 +805,33 @@ templateRoutes.route("/admin").get(authenticateWithRedirect, async (request, res
}).map(async statistic => {
let questions = (await Branches.BranchConfig.loadBranchFromDB(statistic.branch)).questions;
let question = questions.find(q => q.label === statistic.questionName)!;
try {
statistic.responses = statistic.responses.sort((a, b) => {
let aIndex: number = question.options.indexOf(a.response);
let bIndex: number = question.options.indexOf(b.response);

if (aIndex !== -1 && bIndex === -1) {
statistic.responses = statistic.responses.sort((a, b) => {
let aIndex: number = question.options.indexOf(a.response);
let bIndex: number = question.options.indexOf(b.response);
if (!a || !b || !a.response || !b.response) {
return 0;
}
if (aIndex !== -1 && bIndex === -1) {
return -1;
}
if (aIndex === -1 && bIndex !== -1) {
return 1;
}
if (aIndex === -1 && bIndex === -1) {
if (a.response.trim() === "") {
return 1;
}
if (a.response.toLowerCase() < b.response.toLowerCase()) {
return -1;
}
if (aIndex === -1 && bIndex !== -1) {
if (a.response.toLowerCase() > b.response.toLowerCase()) {
return 1;
}
if (aIndex === -1 && bIndex === -1) {
if (a.response.trim() === "") {
return 1;
}
if (a.response.toLowerCase() < b.response.toLowerCase()) {
return -1;
}
if (a.response.toLowerCase() > b.response.toLowerCase()) {
return 1;
}
return 0;
}
return aIndex - bIndex;
});
} catch(e) {
console.trace(e);
return {};
}
return 0;
}
return aIndex - bIndex;
});

return statistic;
}));
Expand Down

0 comments on commit 843af35

Please sign in to comment.