Skip to content

Commit 6077af7

Browse files
committed
fix eslint errors
1 parent ac7e9bd commit 6077af7

File tree

3 files changed

+74
-88
lines changed

3 files changed

+74
-88
lines changed

src/index.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
/* eslint-disable no-console */
22

3-
import express from "express";
4-
import bodyParser from "body-parser";
5-
import { graphqlExpress, graphiqlExpress } from "apollo-server-express";
6-
import { makeExecutableSchema } from "graphql-tools";
7-
import { createServer } from "http";
8-
import { Engine } from "apollo-engine";
3+
import express from 'express';
4+
import bodyParser from 'body-parser';
5+
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
6+
import { makeExecutableSchema } from 'graphql-tools';
7+
import { createServer } from 'http';
8+
import { Engine } from 'apollo-engine';
99

10-
import "./config/db";
11-
import constants from "./config/constants";
12-
import typeDefs from "./graphql/schemas";
13-
import resolvers from "./graphql/resolvers";
10+
import './config/db';
11+
import constants from './config/constants';
12+
import typeDefs from './graphql/schemas';
13+
import resolvers from './graphql/resolvers';
1414

15-
import webhook from "./scripts/webhook";
15+
import webhook from './scripts/webhook';
1616

1717
// Models
18-
import ProcedureModel from "./models/Procedure";
18+
import ProcedureModel from './models/Procedure';
1919

2020
const app = express();
2121

2222
const schema = makeExecutableSchema({
2323
typeDefs,
24-
resolvers
24+
resolvers,
2525
});
2626

2727
if (process.env.ENGINE_API_KEY) {
2828
const engine = new Engine({
2929
engineConfig: { apiKey: process.env.ENGINE_API_KEY },
30-
graphqlPort: constants.PORT
30+
graphqlPort: constants.PORT,
3131
});
3232
engine.start();
3333
app.use(engine.expressMiddleware());
3434
}
3535

3636
app.use(bodyParser.json());
3737

38-
if (process.env.ENVIRONMENT !== "production") {
38+
if (process.env.ENVIRONMENT !== 'production') {
3939
app.use(
4040
constants.GRAPHIQL_PATH,
4141
graphiqlExpress({
42-
endpointURL: constants.GRAPHQL_PATH
43-
})
42+
endpointURL: constants.GRAPHQL_PATH,
43+
}),
4444
);
4545
}
4646

@@ -49,34 +49,34 @@ app.use(constants.GRAPHQL_PATH, (req, res, next) => {
4949
schema,
5050
context: {
5151
// Models
52-
ProcedureModel
52+
ProcedureModel,
5353
},
5454
tracing: true,
55-
cacheControl: true
55+
cacheControl: true,
5656
})(req, res, next);
5757
});
5858

59-
app.post("/webhooks/bundestagio/update", async (req, res) => {
59+
app.post('/webhooks/bundestagio/update', async (req, res) => {
6060
const { data } = req.body;
6161
try {
6262
const updated = await webhook(data);
6363
res.send({
6464
updated,
65-
succeeded: true
65+
succeeded: true,
6666
});
6767
console.log(`Updated: ${updated}`);
6868
} catch (error) {
6969
console.log(error);
7070
res.send({
7171
error,
72-
succeeded: false
72+
succeeded: false,
7373
});
7474
}
7575
});
7676

7777
const graphqlServer = createServer(app);
7878

79-
graphqlServer.listen(constants.PORT, err => {
79+
graphqlServer.listen(constants.PORT, (err) => {
8080
if (err) {
8181
console.error(err);
8282
} else {

src/scripts/import.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import ProgressBar from "cli-progress"; // eslint-disable-line
2-
import program from "commander"; // eslint-disable-line
1+
import ProgressBar from 'cli-progress'; // eslint-disable-line
2+
import program from 'commander'; // eslint-disable-line
33

4-
import createClient from "../graphql/client";
5-
import Procedure from "../models/Procedure";
6-
import getProcedures from "../graphql/queries/getProcedures";
4+
import createClient from '../graphql/client';
5+
import Procedure from '../models/Procedure';
6+
import getProcedures from '../graphql/queries/getProcedures';
77

8-
export default async procedureIds => {
8+
export default async (procedureIds) => {
99
const client = createClient();
1010
// Start Importing
1111
const { data: { procedures } } = await client.query({
1212
query: getProcedures,
1313
variables: { IDs: procedureIds },
14-
fetchPolicy: "network-only"
14+
fetchPolicy: 'network-only',
1515
});
1616
// Start Inserting
17-
const promises = await procedures.map(async bIoProcedure => {
17+
const promises = await procedures.map(async (bIoProcedure) => {
1818
const newBIoProcedure = { ...bIoProcedure };
1919
if (bIoProcedure && bIoProcedure.history) {
2020
const [lastHistory] = newBIoProcedure.history.slice(-1);
21-
const btWithDecisions = bIoProcedure.history.filter(
22-
({ assignment, initiator }) =>
23-
assignment === "BT" && initiator === "2. Beratung"
24-
);
21+
const btWithDecisions = bIoProcedure.history.filter(({ assignment, initiator }) => assignment === 'BT' && initiator === '2. Beratung');
2522
if (btWithDecisions.length > 0) {
2623
newBIoProcedure.voteDate = new Date(btWithDecisions.pop().date);
27-
} else if (newBIoProcedure.currentStatus === "Zurückgezogen") {
24+
} else if (newBIoProcedure.currentStatus === 'Zurückgezogen') {
2825
newBIoProcedure.voteDate = lastHistory.date;
2926
}
3027

@@ -36,8 +33,8 @@ export default async procedureIds => {
3633
{ procedureId: newBIoProcedure.procedureId },
3734
newBIoProcedure,
3835
{
39-
upsert: true
40-
}
36+
upsert: true,
37+
},
4138
);
4239
});
4340
const result = await Promise.all(promises);

src/scripts/webhook.js

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,62 @@
1-
import importProcedures from "./import";
2-
import getProcedureUpdates from "../graphql/queries/getProcedureUpdates";
3-
import createClient from "../graphql/client";
4-
import ProcedureModel from "../models/Procedure";
1+
import importProcedures from './import';
2+
import getProcedureUpdates from '../graphql/queries/getProcedureUpdates';
3+
import createClient from '../graphql/client';
4+
import ProcedureModel from '../models/Procedure';
55

6-
export default async data => {
6+
export default async (data) => {
77
const client = createClient();
88

99
// Count local Data in groups
1010
const groups = await ProcedureModel.aggregate([
1111
{
1212
// Group by Period & Type
1313
$group: {
14-
_id: { period: "$period", type: "$type" },
15-
count: { $sum: 1 }
16-
}
14+
_id: { period: '$period', type: '$type' },
15+
count: { $sum: 1 },
16+
},
1717
},
1818
{
1919
// Group by Period
2020
$group: {
21-
_id: "$_id.period",
22-
types: { $push: { type: "$_id.type", count: "$count" } }
23-
}
21+
_id: '$_id.period',
22+
types: { $push: { type: '$_id.type', count: '$count' } },
23+
},
2424
},
2525
{
2626
// Rename _id Field to period
27-
$project: { _id: 0, period: "$_id", types: 1 }
28-
}
27+
$project: { _id: 0, period: '$_id', types: 1 },
28+
},
2929
]);
3030

3131
const update = [];
32-
await Promise.all(
33-
data.map(async d => {
34-
const period = parseInt(d.period, 10);
35-
const { type, countBefore, changedIds } = d.types.find(
36-
t => t.type === "Gesetzgebung"
37-
);
38-
const group = groups.find(c => c.period === period);
39-
const localCount = group
40-
? group.types.find(ct => ct.type === type).count
41-
: 0;
42-
// Append Changed IDs
43-
update.concat(changedIds);
44-
// Compare Counts Remote & Local
45-
if (countBefore > localCount) {
46-
// Find remote Procedure Updates
47-
const { data: { procedureUpdates } } = await client.query({
48-
query: getProcedureUpdates,
49-
variables: { period, type }
50-
});
32+
await Promise.all(data.map(async (d) => {
33+
const period = parseInt(d.period, 10);
34+
const { type, countBefore, changedIds } = d.types.find(t => t.type === 'Gesetzgebung');
35+
const group = groups.find(c => c.period === period);
36+
const localCount = group ? group.types.find(ct => ct.type === type).count : 0;
37+
// Append Changed IDs
38+
update.concat(changedIds);
39+
// Compare Counts Remote & Local
40+
if (countBefore > localCount) {
41+
// Find remote Procedure Updates
42+
const { data: { procedureUpdates } } = await client.query({
43+
query: getProcedureUpdates,
44+
variables: { period, type },
45+
});
5146
// Find local Procedure Updates
52-
const localProcedureUpdates = await ProcedureModel.find(
53-
{ period, type },
54-
{ procedureId: 1, lastUpdateDate: 1 }
55-
);
47+
const localProcedureUpdates = await ProcedureModel.find(
48+
{ period, type },
49+
{ procedureId: 1, lastUpdateDate: 1 },
50+
);
5651
// Compare
57-
procedureUpdates.forEach(pu => {
58-
const localData = localProcedureUpdates.find(
59-
ld => ld.procedureId === pu.procedureId
60-
);
61-
if (
62-
!localData ||
63-
new Date(localData.lastUpdateDate) < new Date(pu.updatedAt)
64-
) {
65-
update.push(pu.procedureId);
66-
}
67-
});
68-
}
69-
})
70-
);
52+
procedureUpdates.forEach((pu) => {
53+
const localData = localProcedureUpdates.find(ld => ld.procedureId === pu.procedureId);
54+
if (!localData || new Date(localData.lastUpdateDate) < new Date(pu.updatedAt)) {
55+
update.push(pu.procedureId);
56+
}
57+
});
58+
}
59+
}));
7160

7261
// Splitt in Chunks & Update
7362
const chunkSize = 100;

0 commit comments

Comments
 (0)