forked from AshwinGorle/seating-arrangement-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.html
132 lines (113 loc) · 4.54 KB
/
testing.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>testing script</h1>
</body>
<script>
async function createMember(names, emails) {
try{
// const response = await fetch("https://seating-arrangement-backend.vercel.app/api/v1/member", {
const response = await fetch("http://localhost:4321/api/v1/member", {
method: "POST",
headers: {
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjBmNmUyNmJiYTNhZWU2ZTcyM2M1MjMiLCJ1c2VyRW1haWwiOiJhc2h2aW5nb3JsZTEyMzQ1QGdtYWlsLmNvbSIsImlhdCI6MTcxMjI4NzQ0MiwiZXhwIjoxNzEzMTUxNDQyfQ.EVNbQtfyJbAETRKxQZ4XM7xi79ixmWD-_GbcUYS9ZoY",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: names,
phone: "7987248241",
email: emails,
address: "shiv coloni , indore",
preparation: "College study",
monthlySeatFee: 350,
}),
});
const data = await response.json();
console.log("--------- ", data.data[0].name)
}catch(err){
console.log("error in creating : ", names , " -------" , err);
}
}
async function createMultipleMember(start, end){
for(let i=start; i<=end; i++){
names = `G${i}`
emails = `G${i}@gmail.com`
await createMember(names,emails);
}
}
// createMultipleMember(1,50);
async function allotSeatToMember (memberId , seatId, schedule){
try{
// const response = await fetch("https://seating-arrangement-backend.vercel.app/api/v1/member", {
const response = await fetch("http://localhost:4321/api/v1/seat/allocate", {
method: "POST",
headers: {
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjBmNmUyNmJiYTNhZWU2ZTcyM2M1MjMiLCJ1c2VyRW1haWwiOiJhc2h2aW5nb3JsZTEyMzQ1QGdtYWlsLmNvbSIsImlhdCI6MTcxMjI4NzQ0MiwiZXhwIjoxNzEzMTUxNDQyfQ.EVNbQtfyJbAETRKxQZ4XM7xi79ixmWD-_GbcUYS9ZoY",
"Content-Type": "application/json",
},
body: JSON.stringify({
memberId,
seatId,
schedule
}),
});
const data = await response.json();
console.log("--------- ", data.data)
}catch(err){
console.log("error in alloting : ",err);
}
}
async function getAllMembers(){
try{
const response = await fetch("http://localhost:4321/api/v1/member", {
method: "GET",
headers: {
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjBmNmUyNmJiYTNhZWU2ZTcyM2M1MjMiLCJ1c2VyRW1haWwiOiJhc2h2aW5nb3JsZTEyMzQ1QGdtYWlsLmNvbSIsImlhdCI6MTcxMjI4NzQ0MiwiZXhwIjoxNzEzMTUxNDQyfQ.EVNbQtfyJbAETRKxQZ4XM7xi79ixmWD-_GbcUYS9ZoY",
"Content-Type": "application/json",
},
});
const data = await response.json();
const allMembers = data.data;
return allMembers;
}catch(err){
console.log("error in geting all members : ", err);
}
}
async function getAllSeats(){
try{
const response = await fetch("http://localhost:4321/api/v1/seat", {
method: "GET",
headers: {
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjBmNmUyNmJiYTNhZWU2ZTcyM2M1MjMiLCJ1c2VyRW1haWwiOiJhc2h2aW5nb3JsZTEyMzQ1QGdtYWlsLmNvbSIsImlhdCI6MTcxMjI4NzQ0MiwiZXhwIjoxNzEzMTUxNDQyfQ.EVNbQtfyJbAETRKxQZ4XM7xi79ixmWD-_GbcUYS9ZoY",
"Content-Type": "application/json",
},
});
const data = await response.json();
const allSeats = data.data;
return allSeats;
}catch(err){
console.log("error in geting all seats : ", err);
}
}
async function allotMultipleSeats(){
try{
const schedule = ["morning" , "noon", "evening" ,"fullDay"]
const allMembers = await getAllMembers();
const allSeats = await getAllSeats();
for(let i=0; i<allMembers.length; i++){
await allotSeatToMember(allMembers[i]._id, allSeats[i]._id, schedule[Math.floor(Math.random() * 4)]);
}
console.log("all seats alloted---------------!")
}catch(err){
console.log("create multiple seat error : ", err)
}
}
// allotMultipleSeats();
</script>
</html>
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NjA5OWJiMDRlMjZmNTFiMDY2MjIzOWEiLCJ1c2VyRW1haWwiOiJvd25lckJAZ21haWwuY29tIiwiaWF0IjoxNzExOTA1NzEyLCJleHAiOjE3MTI3Njk3MTJ9.K8wxb6Mh6_S-1m0tpV5haueJYEbb1qytOHy7ujSHw_8