-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy patharticle.ts
More file actions
38 lines (37 loc) · 1.08 KB
/
article.ts
File metadata and controls
38 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as transforms from "../utils/transforms";
import request from "../utils/request";
/**
* Returns articles list from backend.
*
*/
export const getAll = (): Promise<{
articles: { title: string; id: string }[];
statusCode: number;
}> =>
new Promise((resolve, reject) => {
request
.get("/api/articles")
.query({
"fields[node--article]": "id",
})
// Tell superagent to consider any valid Drupal response as successful.
// Later we can capture error codes if needed.
.ok((resp: any) => resp.statusCode)
.then((response: any) => {
resolve({
// eslint-disable-next-line max-len
articles:
response.statusCode === 200
? response.body.data.map((article: any) =>
transforms.article(article)
)
: [],
statusCode: response.statusCode,
});
})
.catch((error: any) => {
// eslint-disable-next-line no-console
console.error("Could not fetch the articles.", error);
reject(error);
});
});