Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (41 loc) · 1.62 KB
/
Copy pathapp.js
File metadata and controls
55 lines (41 loc) · 1.62 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
const express = require('express')
const database = require("./database.js")
const app = express()
const port = 3000
app.get('/get_all_cities', (req, res) => {
var response_string = ""
database.all('SELECT * FROM Cities', (err, rows) => {
for(const row of rows){
row_readable = `${row.ZIP}: ${row.CityName}`
if(row.ZIP == 83278){
response_string += "<b>" + row_readable + "</b><br/>"
}else{
response_string += row_readable + "<br/>"
}
}
res.send(response_string)
})
})
/*
Task 1: Create a new route /get_all_courses that produces
the following type of output: InfoSys with 90% attendence rate (Study Program: EC) in 83278, Traunstein
Task 2: Highlight courses with an attendence rate < 50%
with a red color (see CSS).
*/
app.get('/get_all_courses', (req, res) => {
var response_string = ""
database.all('SELECT c.courseName, c.degreeProgram, l.ZIP, cit.CityName, c.attendanceRate FROM Courses c JOIN Locations l ON c.locationID = l.LocationID JOIN Cities cit ON l.ZIP = cit.ZIP', (err, rows) => {
for(const row of rows){
row_readable = `${row.courseName} (Study Program: ${row.degreeProgram}) in ${row.ZIP}, ${row.CityName}`
if(row.attendanceRate < 50){
response_string += "<span style='color:red'>" + row_readable + "</span><br/>"
}else{
response_string += row_readable + "<br/>"
}
}
res.send(response_string)
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})