Skip to content

Commit 76c2c09

Browse files
committed
add named voting results
1 parent 1e7cfc5 commit 76c2c09

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

src/graphql/schemas/Procedure.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ enum ProcedureType {
55
HOT
66
}
77
8+
type VoteResult {
9+
yes: Int
10+
no: Int
11+
abstination: Int
12+
notVote: Int
13+
}
14+
815
type Procedure {
916
_id: ID!
1017
title: String!
@@ -19,6 +26,7 @@ type Procedure {
1926
submissionDate: Date
2027
activityIndex: ActivityIndex
2128
importantDocuments: [Document]
29+
voteResults: VoteResult
2230
}
2331
2432
type Query {

src/models/Procedure.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ProcedureSchema = new Schema(
2525
yes: { type: Number, required: true },
2626
no: { type: Number, required: true },
2727
abstination: { type: Number, required: true },
28+
notVote: { type: Number, required: true },
2829
},
2930
},
3031
{ timestamps: true },

src/scripts/import.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
import _ from 'lodash';
2+
13
import createClient from '../graphql/client';
24
import Procedure from '../models/Procedure';
35
import getProcedures from '../graphql/queries/getProcedures';
46

7+
const deputiesNumber = {
8+
8: 518,
9+
9: 519,
10+
10: 520,
11+
11: 663,
12+
12: 662,
13+
13: 672,
14+
14: 665,
15+
15: 601,
16+
16: 611,
17+
17: 620,
18+
18: 630,
19+
19: 709,
20+
};
21+
522
export default async (procedureIds) => {
623
const client = createClient();
724
// Start Importing
@@ -21,7 +38,7 @@ export default async (procedureIds) => {
2138
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
2239
newBIoProcedure.voteDate = lastHistory.date;
2340
}
24-
let voteResults = false;
41+
let voteResults;
2542
procedures.history.some((h) => {
2643
if (h.decision) {
2744
return h.decision.some((decision) => {
@@ -31,6 +48,9 @@ export default async (procedureIds) => {
3148
yes: vResults[0],
3249
no: vResults[1],
3350
abstination: vResults[2],
51+
notVote:
52+
deputiesNumber[bIoProcedure.period] -
53+
vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0),
3454
};
3555
return true;
3656
}
@@ -47,7 +67,9 @@ export default async (procedureIds) => {
4767
}
4868
return Procedure.findOneAndUpdate(
4969
{ procedureId: newBIoProcedure.procedureId },
50-
newBIoProcedure,
70+
_(newBIoProcedure)
71+
.omitBy(x => _.isNull(x) || _.isUndefined(x))
72+
.value(),
5173
{
5274
upsert: true,
5375
},

src/scripts/importAll.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
import _ from 'lodash';
2+
13
import createClient from '../graphql/client';
24
import Procedure from '../models/Procedure';
35
import getAllProcedures from '../graphql/queries/getAllProcedures';
46

7+
const deputiesNumber = {
8+
8: 518,
9+
9: 519,
10+
10: 520,
11+
11: 663,
12+
12: 662,
13+
13: 672,
14+
14: 665,
15+
15: 601,
16+
16: 611,
17+
17: 620,
18+
18: 630,
19+
19: 709,
20+
};
21+
522
export default async () => {
623
const client = createClient();
724
console.log('Start Importing');
@@ -22,7 +39,7 @@ export default async () => {
2239
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
2340
newBIoProcedure.voteDate = lastHistory.date;
2441
}
25-
let voteResults = false;
42+
let voteResults;
2643
bIoProcedure.history.some((h) => {
2744
if (h.decision) {
2845
return h.decision.some((decision) => {
@@ -32,6 +49,9 @@ export default async () => {
3249
yes: vResults[0],
3350
no: vResults[1],
3451
abstination: vResults[2],
52+
notVote:
53+
deputiesNumber[bIoProcedure.period] -
54+
vResults.reduce((pv, cv) => pv + parseInt(cv, 10), 0),
3555
};
3656
return true;
3757
}
@@ -40,16 +60,19 @@ export default async () => {
4060
}
4161
return false;
4262
});
43-
console.log(newBIoProcedure.procedureId, voteResults);
63+
4464
newBIoProcedure.voteResults = voteResults;
4565

4666
newBIoProcedure.lastUpdateDate = lastHistory.date;
4767

4868
newBIoProcedure.submissionDate = newBIoProcedure.history[0].date;
4969
}
70+
5071
await Procedure.findOneAndUpdate(
5172
{ procedureId: newBIoProcedure.procedureId },
52-
newBIoProcedure,
73+
_(newBIoProcedure)
74+
.omitBy(x => _.isNull(x) || _.isUndefined(x))
75+
.value(),
5376
{
5477
upsert: true,
5578
},

0 commit comments

Comments
 (0)