Skip to content

Commit 1e7cfc5

Browse files
committed
- add import voteResults
- add import all webhook (commented)
1 parent b9381a1 commit 1e7cfc5

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/graphql/queries/getAllProcedures.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import gql from 'graphql-tag';
22

33
export default gql`
4-
query allProcedures() {
5-
allProcedures() {
4+
query allProcedures {
5+
allProcedures {
66
title
77
procedureId
88
type
@@ -16,6 +16,8 @@ export default gql`
1616
initiator
1717
decision {
1818
tenor
19+
type
20+
comment
1921
}
2022
date
2123
}

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import typeDefs from './graphql/schemas';
1313
import resolvers from './graphql/resolvers';
1414

1515
import webhook from './scripts/webhook';
16+
import importAll from './scripts/importAll';
1617

1718
import auth from './express/auth';
1819

@@ -83,6 +84,9 @@ app.post('/webhooks/bundestagio/update', async (req, res) => {
8384
}
8485
});
8586

87+
// Darf in Production nicht ausführbar sein!
88+
// app.get('/webhooks/bundestagio/import-all', importAll);
89+
8690
const graphqlServer = createServer(app);
8791

8892
graphqlServer.listen(constants.PORT, (err) => {

src/scripts/import.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ export default async (procedureIds) => {
2222
newBIoProcedure.voteDate = lastHistory.date;
2323
}
2424
let voteResults = false;
25-
procedures.history.forEach((h) => {
25+
procedures.history.some((h) => {
2626
if (h.decision) {
27-
return h.decision.forEach((decision) => {
27+
return h.decision.some((decision) => {
2828
if (decision.type === 'Namentliche Abstimmung') {
29-
return (voteResults = {
30-
yes: decision.comment,
31-
no: decision.comment,
32-
abstination: decision.comment,
33-
});
29+
const vResults = decision.comment.split(':');
30+
voteResults = {
31+
yes: vResults[0],
32+
no: vResults[1],
33+
abstination: vResults[2],
34+
};
35+
return true;
3436
}
37+
return false;
3538
});
3639
}
40+
return false;
3741
});
42+
newBIoProcedure.voteResults = voteResults;
3843

3944
newBIoProcedure.lastUpdateDate = lastHistory.date;
4045

scripts/importAll.js renamed to src/scripts/importAll.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import client from '../src/graphql/client';
2-
import Procedure from '../src/models/Procedure';
3-
import getAllProcedures from '../src/graphql/queries/getAllProcedures';
1+
import createClient from '../graphql/client';
2+
import Procedure from '../models/Procedure';
3+
import getAllProcedures from '../graphql/queries/getAllProcedures';
44

5-
require('../src/config/db');
6-
7-
(async () => {
5+
export default async () => {
6+
const client = createClient();
87
console.log('Start Importing');
98
const { data: { allProcedures } } = await client.query({
109
query: getAllProcedures,
1110
// variables: {},
1211
});
1312
console.log(allProcedures.map(({ procedureId }) => procedureId));
1413
console.log('Start Inserting');
14+
// Start Inserting
1515
await allProcedures.forEach(async (bIoProcedure) => {
1616
const newBIoProcedure = { ...bIoProcedure };
1717
if (bIoProcedure && bIoProcedure.history) {
@@ -22,6 +22,26 @@ require('../src/config/db');
2222
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
2323
newBIoProcedure.voteDate = lastHistory.date;
2424
}
25+
let voteResults = false;
26+
bIoProcedure.history.some((h) => {
27+
if (h.decision) {
28+
return h.decision.some((decision) => {
29+
if (decision.type === 'Namentliche Abstimmung') {
30+
const vResults = decision.comment.split(':');
31+
voteResults = {
32+
yes: vResults[0],
33+
no: vResults[1],
34+
abstination: vResults[2],
35+
};
36+
return true;
37+
}
38+
return false;
39+
});
40+
}
41+
return false;
42+
});
43+
console.log(newBIoProcedure.procedureId, voteResults);
44+
newBIoProcedure.voteResults = voteResults;
2545

2646
newBIoProcedure.lastUpdateDate = lastHistory.date;
2747

@@ -36,4 +56,4 @@ require('../src/config/db');
3656
);
3757
});
3858
console.log('Imported everything!'); // eslint-disable-line
39-
})();
59+
};

0 commit comments

Comments
 (0)