Skip to content

Commit 8eab69b

Browse files
authored
Merge pull request #43 from demokratie-live/sprint#9/Antrag
add proceduretype "Antrag"
2 parents 2bdf285 + 3a3a84f commit 8eab69b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/scripts/importAll.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const deputiesNumber = {
1919
19: 709,
2020
};
2121

22-
export default async () => {
22+
const pastStatus = ['Zurückgezogen', 'Abgelehnt', 'Angenommen'];
23+
24+
export default async (req, res) => {
2325
const client = createClient();
2426
console.log('Start Importing');
2527
const { data: { allProcedures } } = await client.query({
@@ -36,7 +38,7 @@ export default async () => {
3638
const btWithDecisions = bIoProcedure.history.filter(({ assignment, initiator }) => assignment === 'BT' && initiator === '2. Beratung');
3739
if (btWithDecisions.length > 0) {
3840
newBIoProcedure.voteDate = new Date(btWithDecisions.pop().date);
39-
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
41+
} else if (pastStatus.some(status => status === newBIoProcedure.currentStatus)) {
4042
newBIoProcedure.voteDate = lastHistory.date;
4143
}
4244
let voteResults;
@@ -80,4 +82,5 @@ export default async () => {
8082
);
8183
});
8284
console.log('Imported everything!'); // eslint-disable-line
85+
res.send('Imported everything!');
8386
};

src/scripts/webhook.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export default async (data) => {
3131
const update = [];
3232
await Promise.all(data.map(async (d) => {
3333
const period = parseInt(d.period, 10);
34-
const { type, countBefore, changedIds } = d.types.find(t => t.type === 'Gesetzgebung');
34+
const { type, countBefore, changedIds } = d.types.find(t => t.type === 'Gesetzgebung' || t.type === 'Antrag');
3535
const group = groups.find(c => c.period === period);
36-
const localCount = group ? group.types.find(ct => ct.type === type).count : 0;
36+
const localGroup = group ? group.types.find(ct => ct.type === type) : null;
37+
const localCount = localGroup ? localGroup.count : 0;
3738
// Append Changed IDs
3839
update.concat(changedIds);
3940
// Compare Counts Remote & Local
@@ -43,18 +44,18 @@ export default async (data) => {
4344
query: getProcedureUpdates,
4445
variables: { period, type },
4546
});
46-
// Find local Procedure Updates
47+
// Find local Procedure Updates
4748
const localProcedureUpdates = await ProcedureModel.find(
4849
{ period, type },
4950
{ procedureId: 1, bioUpdateAt: 1 },
5051
);
51-
// Compare
52+
// Compare
5253
procedureUpdates.forEach((pu) => {
5354
const localData = localProcedureUpdates.find(ld => ld.procedureId === pu.procedureId);
5455
if (
5556
!localData ||
56-
(pu.bioUpdateAt &&
57-
new Date(localData.bioUpdateAt).getTime() !== new Date(pu.bioUpdateAt).getTime())
57+
(pu.bioUpdateAt &&
58+
new Date(localData.bioUpdateAt).getTime() !== new Date(pu.bioUpdateAt).getTime())
5859
) {
5960
update.push(pu.procedureId);
6061
}

0 commit comments

Comments
 (0)