-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (79 loc) · 2.08 KB
/
Copy pathindex.js
File metadata and controls
85 lines (79 loc) · 2.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { submit } from "json-graphql-parser";
import { Log } from "../../../log/index.js";
import { FETH_ALL_PLAYS } from "./query.js";
import {
toKebabCase,
toPascalcase,
toSanitized,
toSlug,
toTitleCase,
toTitleCaseTrimmed,
} from "../../../util/string.js";
// const URL = `${process.env.NHOST_ROTOCOL}://${process.env.NHOST_SERVER}/${process.env.NHOST_ENDPOINT}`;
const URL = "https://rgkjmwftqtbpayoyolwh.hasura.ap-southeast-1.nhost.run/v1/graphql";
export const loadPlay = async (id) => {
const res = await loadPlayAsync(id);
return res;
};
export const loadPlayAsync = (id) => {
Log.log(`Reading play information of "${id}"`);
return submit(
{
...FETH_ALL_PLAYS,
...{
where: {
operator: "",
clause: [
{
field: "id",
operator: "eq",
value: id,
type: "string",
},
],
},
},
},
URL
)
.then((res) => {
const play = processPlayInformation(res[0]);
return play;
})
.catch((err) => {
console.error("Error occured");
console.error(
`Status ${err.response.status} : ${err.response.statusText}`
);
});
};
export const loadAllPlays = async () => {
const res = await loadAllPlaysAsync(id);
return res;
};
export const loadAllPlaysAsync = () => {
Log.log(`Getting all plays`);
return submit(FETH_ALL_PLAYS, URL)
.then((res) => {
const play_list = [];
res.forEach((play) => {
play_list.push(processPlayInformation(play));
});
return play_list;
})
.catch((err) => {
console.error("Error occured");
console.error(
`Status ${err.response.status} : ${err.response.statusText}`
);
});
};
const processPlayInformation = (play) => {
play.kebab_name = play.slug;
play.pascal_name = toPascalcase(toSanitized(play.name));
play.title_string = toTitleCase(play.name);
play.title_name = toTitleCaseTrimmed(play.name);
play.title_name_sanitized = toSanitized(play.title_name);
play.level = play.level.name;
return play;
};