-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
211 lines (176 loc) · 6.04 KB
/
index.js
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
var express = require('express');
var app = express();
var bodyParser = require('body-parser')
app.use(bodyParser.json());
const {conn, sql} = require('./dbconfig')
// app.post("/register", function (req, res) {
// res.send("Hello")
// });
// app.get("", function (req, res) {
// res.send('<form method="POST" action="/register"><button>Register</button></form>')
// });
app.get("/pokemon", async function (req, res) {
var pool = await conn;
var sql_query = req.query;
// if sql_query.id is not Null
var sqlString = "SELECT * FROM Pokemon";
return await pool.request().query(sqlString, function (err, data) {
res.send(data.recordset)
});
});
app.get("/pokemon/:id", async function (req, res) {
var id = req.params.id;
var pool = await conn;
var sqlString = "SELECT * FROM Pokemon where pokemonid = @varId";
return await pool.request().input('varId', sql.Int, id).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/pokemon/name/:pokename", async function (req, res) {
var name = req.params.pokename;
var pool = await conn;
console.log(name)
var sqlString = "SELECT * FROM pokemon where pname = @varName";
return await pool.request().input('varName', sql.NVarChar, name).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/pokemon/move/name/:name", async function (req, res) {
var name = req.params.name;
var pool = await conn;
console.log(name)
var sqlString = "SELECT * FROM Pokemon_Move_Name(@varName)";
return await pool.request().input('varName', sql.NVarChar, name).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/pokemon/move/id/:id", async function (req, res) {
var id = req.params.id;
var pool = await conn;
var sqlString = "SELECT * FROM Pokemon_Move_Id(@varId)";
return await pool.request().input('varId', sql.Int, id).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/move", async function (req, res) {
var pool = await conn;
var sqlString = "SELECT * FROM moves";
return await pool.request().query(sqlString, function (err, data) {
res.send(data.recordset)
});
});
app.get("/move/:id", async function (req, res) {
var id = req.params.id;
var pool = await conn;
var sqlString = "SELECT * FROM moves where moveid = @varId";
return await pool.request().input('varId', sql.Int, id).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/move/name/:movename", async function (req, res) {
var name = req.params.movename;
var pool = await conn;
console.log(name)
var sqlString = "SELECT * FROM moves where mname = @varName";
return await pool.request().input('varName', sql.NVarChar, name).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/type", async function (req, res) {
var pool = await conn;
var sqlString = "SELECT * FROM types";
return await pool.request().query(sqlString, function (err, data) {
res.send(data.recordset)
});
});
app.get("/type/:id", async function (req, res) {
var id = req.params.id;
var pool = await conn;
var sqlString = "SELECT * FROM types where typeid = @varId";
return await pool.request().input('varId', sql.Int, id).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/type/name/:typename", async function (req, res) {
var name = req.params.typename;
var pool = await conn;
console.log(name)
var sqlString = "SELECT * FROM types where tname = @varName";
return await pool.request().input('varName', sql.NVarChar, name).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/ability", async function (req, res) {
var pool = await conn;
var sqlString = "SELECT * FROM abilities";
return await pool.request().query(sqlString, function (err, data) {
res.send(data.recordset)
});
});
app.get("/ability/:id", async function (req, res) {
var id = req.params.id;
var pool = await conn;
var sqlString = "SELECT * FROM abilities where abilityid = @varId";
return await pool.request().input('varId', sql.Int, id).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
app.get("/ability/name/:abilityname", async function (req, res) {
var name = req.params.abilityname;
var pool = await conn;
console.log(name)
var sqlString = "SELECT * FROM abilities where aname = @varName";
return await pool.request().input('varName', sql.NVarChar, name).query(sqlString, function (err, data) {
if (data.recordset.length > 0) {
res.send(data.recordset);
} else {
res.send(null);
}
});
});
// app.put("/update", function (req, res) {
// res.send("Hello")
// });
// app.delete("/delete", function (req, res) {
// res.send("Hello")
// });
const PORT = process.env.PORT || 3000;
//Open host
app.listen(PORT, function () {
});