Skip to content

Commit 414538a

Browse files
committed
Add lodash and eslint
+ Fix initial lint errors based on airbnb base config + Remove procedures without an abstract (it is used as content and contentExcerpt which is required by HC)
1 parent 6265a2e commit 414538a

File tree

4 files changed

+1082
-41
lines changed

4 files changed

+1082
-41
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
extends: "airbnb-base",
3+
rules: { "newline-per-chained-call": [2] }
4+
};

index.mjs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1+
/* eslint no-console: off */
12
import fetch from 'node-fetch';
3+
import _ from 'lodash';
24

3-
const hcBackendUrl = 'http://localhost:3030'
4-
const bundestagGraphqlUrl = 'http://localhost:3000/graphql'
5-
const query = '{"query": "{procedures(type: PREPARATION) { title abstract }}"}';
5+
const hcBackendUrl = 'http://localhost:3030';
6+
const bundestagGraphqlUrl = 'http://localhost:3000/graphql';
7+
const query = `{
8+
procedures(type: PREPARATION) {
9+
title
10+
abstract
11+
}
12+
}`;
613

714
class User {
815
login(email, password) {
916
const formData = {
10-
email: email,
11-
password: password,
17+
email,
18+
password,
1219
strategy: 'local',
13-
}
20+
};
1421
return fetch(`${hcBackendUrl}/authentication`, {
1522
method: 'post',
1623
body: JSON.stringify(formData),
17-
headers: { 'Content-Type': 'application/json' }
18-
}).then((response) => {
19-
return response.json()
20-
}).then((json) => {
24+
headers: { 'Content-Type': 'application/json' },
25+
}).then(response => response.json()).then((json) => {
2126
this.accessToken = json.accessToken;
2227
return true;
2328
});
2429
}
2530

26-
contribute(contribution){
31+
contribute(contribution) {
2732
return fetch(`${hcBackendUrl}/contributions`, {
2833
method: 'post',
29-
body: JSON.stringify(contribution),
30-
headers: {
31-
'Authorization': `Bearer ${this.accessToken}`,
32-
'Content-Type': 'application/json'
33-
}
34-
}).then((response) => {
35-
return response.json();
36-
})
34+
body: JSON.stringify(contribution),
35+
headers: {
36+
Authorization: `Bearer ${this.accessToken}`,
37+
'Content-Type': 'application/json',
38+
},
39+
}).then(response => response.json());
3740
}
3841
}
3942

40-
async function bundestagProcedures(){
41-
return await fetch(bundestagGraphqlUrl, {
42-
method: 'post',
43-
body: query,
44-
headers: { 'Content-Type': 'application/json' }
45-
}).then((response) => {
46-
return response.json()
47-
}).then((json) => {
48-
return json.data.procedures;
49-
});
43+
async function bundestagProcedures() {
44+
return fetch(bundestagGraphqlUrl, {
45+
method: 'post',
46+
body: JSON.stringify({ query }),
47+
headers: { 'Content-Type': 'application/json' },
48+
}).then(response => response.json()).then(json => json.data.procedures);
5049
}
5150

5251

53-
54-
5552
async function main() {
56-
let user = new User();
53+
const user = new User();
5754
await user.login('[email protected]', '1234');
58-
const procedures = await bundestagProcedures();
59-
if (procedures.length > 0){
55+
let procedures = await bundestagProcedures();
56+
procedures = procedures.filter((p) => { return ! _.isNil(p.abstract) });
57+
58+
59+
if (_.isEmpty(procedures)) {
60+
console.log('No procedures found!');
61+
} else {
6062
const contribution = {
6163
title: procedures[0].title,
6264
content: procedures[0].abstract,
6365
contentExcerpt: procedures[0].abstract,
64-
type: "post",
65-
language: "de",
66-
categoryIds: ["5ac7768f8d655d2ee6d48fe4"] // democracy-politics
67-
}
66+
type: 'post',
67+
language: 'de',
68+
categoryIds: ['5ac7768f8d655d2ee6d48fe4'], // democracy-politics
69+
};
6870
const response = await user.contribute(contribution);
6971
console.log(response);
70-
} else {
71-
console.log("No procedures found!");
7272
}
7373
}
7474

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"lodash": "^4.17.5",
34
"node-fetch": "^2.1.2"
45
},
56
"name": "human-connection-api-nodejs-client",
@@ -10,6 +11,12 @@
1011
"author": "Robert Schaefer <[email protected]>",
1112
"license": "MIT",
1213
"scripts": {
13-
"start" : "node --experimental-modules index.mjs"
14+
"lint": "eslint --ext mjs .",
15+
"start": "node --experimental-modules index.mjs"
16+
},
17+
"devDependencies": {
18+
"eslint": "^4.19.1",
19+
"eslint-config-airbnb-base": "^12.1.0",
20+
"eslint-plugin-import": "^2.11.0"
1421
}
1522
}

0 commit comments

Comments
 (0)