-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateUserdata.js
More file actions
67 lines (59 loc) · 1.52 KB
/
createUserdata.js
File metadata and controls
67 lines (59 loc) · 1.52 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
const LOCALSTORAGE_TOKEN = "virtuallabs-token";
const token = localStorage.getItem(LOCALSTORAGE_TOKEN);
if (!token) {
localStorage.setItem(
LOCALSTORAGE_TOKEN,
"TOKEN HERE"
);
}
const createForm = document.querySelector("#userdata-create");
const createUserdata = (solverId, datas) => `
mutation {
createUserdata ( input : {
solverId : ${solverId},
datas : ${JSON.stringify(datas)}
}) {
ok
error
}
}`;
const createUserdataCompleted = ({ data }) => {
const {
createUserdata: { ok, error },
} = data;
if (!ok) {
console.log(error);
return;
}
console.log("createUserdataCompleted");
};
const mutation = (ev) => {
console.log("저장");
ev.preventDefault();
const userdata = JSON.stringify(coords);
const solverId = document.querySelector("#solverId").value;
const query = createUserdata(solverId, userdata);
console.log(query);
// mutation {
// createUserdata ( input : {
// solverId : 1,
// datas : "[object Object]"
// }) {
// ok
// error
// }
// }
const options = {
method: "post",
headers: {
"Content-Type": "application/json",
"x-jwt": token,
},
body: JSON.stringify({ query }),
};
fetch(`https://kaist.edison.re.kr/graphql/`, options)
.then((res) => res.json())
.then(createUserdataCompleted);
createForm.reset();
};
createForm.addEventListener("submit", mutation);