Skip to content

Commit d2bec20

Browse files
committed
import on count missmatch
1 parent c816fc9 commit d2bec20

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/graphql/queries/getProcedureUpdates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default gql`
44
query procedureUpdates($pageSize: Int, $period: [Int!], $type: [String!]) {
55
procedureUpdates(pageSize: $pageSize, period: $period, type: $type) {
66
procedureId
7-
lastUpdateDate
7+
updatedAt
88
}
99
}
1010
`;

src/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ app.post('/webhooks/bundestagio/update', async (req, res) => {
6767
update = update.concat(value.changedIds);
6868
return null;
6969
});
70-
const updated = await importProcedures(update);
70+
let updated = await importProcedures(update);
7171

7272
const counts = await Procedure.aggregate([{
7373
$group: {
@@ -96,20 +96,27 @@ app.post('/webhooks/bundestagio/update', async (req, res) => {
9696
types: 1,
9797
},
9898
}]);
99-
Object.keys(data).map(async (objectKey) => {
99+
const update2 = [];
100+
await Promise.all(Object.keys(data).map(async (objectKey) => {
100101
const { count } = data[objectKey].find(d => d.type === 'Gesetzgebung');
101102
const localCount = counts.find(d => d.period === parseInt(objectKey, 10)).types.find(d => d.type === 'Gesetzgebung').count;
102103
if (count > localCount) {
103-
console.log(count);
104-
console.log(localCount);
105104
const PAGE_SIZE = 20;
106105
const { data: { procedureUpdates } } = await client.query({
107106
query: getProcedureUpdates,
108107
variables: { pageSize: PAGE_SIZE, period: parseInt(objectKey, 10), type: 'Gesetzgebung' },
109108
});
110-
console.log(procedureUpdates);
109+
const localProcedureUpdates = await Procedure.find({ period: parseInt(objectKey, 10), type: 'Gesetzgebung' }, { procedureId: 1, lastUpdateDate: 1 });
110+
procedureUpdates.map((data2) => {
111+
const localData = localProcedureUpdates.find(d => d.procedureId === data2.procedureId);
112+
if (!localData || new Date(localData.lastUpdateDate) < new Date(data2.updatedAt)) {
113+
update2.push(data2.procedureId);
114+
}
115+
return null;
116+
});
111117
}
112-
});
118+
}));
119+
updated += await importProcedures(update2);
113120
res.send({
114121
updated,
115122
succeeded: true,

0 commit comments

Comments
 (0)