Skip to content

Commit 3955e8f

Browse files
committed
import custom vote results
1 parent 6a4edcc commit 3955e8f

File tree

2 files changed

+76
-44
lines changed

2 files changed

+76
-44
lines changed

src/scripts/import.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,45 @@ export default async (procedureIds) => {
4040
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
4141
newBIoProcedure.voteDate = lastHistory.date;
4242
}
43+
44+
// check vote results
4345
let voteResults;
44-
bIoProcedure.history.some((h) => {
45-
if (h.decision) {
46-
return h.decision.some((decision) => {
47-
if (decision.type === 'Namentliche Abstimmung') {
48-
const voteResultsRegEx = /(\d{1,3}:\d{1,3}:\d{1,3})/;
49-
const voteResultsProto = decision.comment.match(voteResultsRegEx);
50-
const vResults = voteResultsProto ? voteResultsProto[0].split(':') : null;
51-
voteResults = {
52-
yes: vResults ? vResults[0] : null,
53-
no: vResults ? vResults[1] : null,
54-
abstination: vResults ? vResults[2] : null,
55-
notVote:
56-
deputiesNumber[bIoProcedure.period] -
57-
(vResults ? vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0) : 0),
58-
};
59-
return true;
60-
}
61-
return false;
62-
});
63-
}
64-
return false;
65-
});
46+
if (
47+
bIoProcedure.customData &&
48+
bIoProcedure.customData.voteResults &&
49+
(bIoProcedure.customData.voteResults.yes ||
50+
bIoProcedure.customData.voteResults.abstination ||
51+
bIoProcedure.customData.voteResults.no)
52+
) {
53+
voteResults = {
54+
yes: bIoProcedure.customData.voteResults.yes,
55+
abstination: bIoProcedure.customData.voteResults.abstination,
56+
no: bIoProcedure.customData.voteResults.no,
57+
};
58+
} else {
59+
bIoProcedure.history.some((h) => {
60+
if (h.decision) {
61+
return h.decision.some((decision) => {
62+
if (decision.type === 'Namentliche Abstimmung') {
63+
const voteResultsRegEx = /(\d{1,3}:\d{1,3}:\d{1,3})/;
64+
const voteResultsProto = decision.comment.match(voteResultsRegEx);
65+
const vResults = voteResultsProto ? voteResultsProto[0].split(':') : null;
66+
voteResults = {
67+
yes: vResults ? vResults[0] : null,
68+
no: vResults ? vResults[1] : null,
69+
abstination: vResults ? vResults[2] : null,
70+
notVote:
71+
deputiesNumber[bIoProcedure.period] -
72+
(vResults ? vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0) : 0),
73+
};
74+
return true;
75+
}
76+
return false;
77+
});
78+
}
79+
return false;
80+
});
81+
}
6682
newBIoProcedure.voteResults = voteResults;
6783

6884
newBIoProcedure.lastUpdateDate = lastHistory.date;

src/scripts/importAll.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,45 @@ export default async (req, res) => {
4141
} else if (pastStatus.some(status => status === newBIoProcedure.currentStatus)) {
4242
newBIoProcedure.voteDate = lastHistory.date;
4343
}
44-
let voteResults;
45-
bIoProcedure.history.some((h) => {
46-
if (h.decision) {
47-
return h.decision.some((decision) => {
48-
if (decision.type === 'Namentliche Abstimmung') {
49-
const voteResultsRegEx = /(\d{1,3}:\d{1,3}:\d{1,3})/;
50-
const vResults = decision.comment.match(voteResultsRegEx)[0].split(':');
51-
voteResults = {
52-
yes: vResults[0],
53-
no: vResults[1],
54-
abstination: vResults[2],
55-
notVote:
56-
deputiesNumber[bIoProcedure.period] -
57-
vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0),
58-
};
59-
return true;
60-
}
61-
return false;
62-
});
63-
}
64-
return false;
65-
});
6644

45+
// check vote results
46+
let voteResults;
47+
if (
48+
bIoProcedure.customData &&
49+
bIoProcedure.customData.voteResults &&
50+
(bIoProcedure.customData.voteResults.yes ||
51+
bIoProcedure.customData.voteResults.abstination ||
52+
bIoProcedure.customData.voteResults.no)
53+
) {
54+
voteResults = {
55+
yes: bIoProcedure.customData.voteResults.yes,
56+
abstination: bIoProcedure.customData.voteResults.abstination,
57+
no: bIoProcedure.customData.voteResults.no,
58+
};
59+
} else {
60+
bIoProcedure.history.some((h) => {
61+
if (h.decision) {
62+
return h.decision.some((decision) => {
63+
if (decision.type === 'Namentliche Abstimmung') {
64+
const voteResultsRegEx = /(\d{1,3}:\d{1,3}:\d{1,3})/;
65+
const voteResultsProto = decision.comment.match(voteResultsRegEx);
66+
const vResults = voteResultsProto ? voteResultsProto[0].split(':') : null;
67+
voteResults = {
68+
yes: vResults ? vResults[0] : null,
69+
no: vResults ? vResults[1] : null,
70+
abstination: vResults ? vResults[2] : null,
71+
notVote:
72+
deputiesNumber[bIoProcedure.period] -
73+
(vResults ? vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0) : 0),
74+
};
75+
return true;
76+
}
77+
return false;
78+
});
79+
}
80+
return false;
81+
});
82+
}
6783
newBIoProcedure.voteResults = voteResults;
6884

6985
newBIoProcedure.lastUpdateDate = lastHistory.date;

0 commit comments

Comments
 (0)