-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathprofessors.ts
54 lines (44 loc) · 1.39 KB
/
professors.ts
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
/**
@module ProfessorsRoute
*/
import express, { Request } from 'express';
import { getProfessorQuery } from '../helpers/gql';
const router = express.Router();
/**
* PPAPI proxy for professor data
*/
router.get('/api', function (req: Request<never, unknown, never, { ucinetid: string }>, res) {
const r = fetch(process.env.PUBLIC_API_URL + 'instructors/' + req.query.ucinetid);
r.then((response) => response.json()).then((data) => res.send(data));
});
/**
* PPAPI proxy for professor data
*/
router.post('/api/batch', (req: Request<never, unknown, { professors: string[] }, never>, res) => {
if (req.body.professors.length == 0) {
res.json({});
} else {
const r = fetch(process.env.PUBLIC_API_GRAPHQL_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: getProfessorQuery(req.body.professors),
}),
});
r.then((response) => response.json()).then((data) => res.json(data.data));
}
});
/**
* PPAPI proxy for grade distribution
*/
router.get('/api/grades/:name', function (req, res) {
const r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?instructor=' + encodeURIComponent(req.params.name));
let status = 200;
r.then((response) => {
status = response.status;
return response.json();
}).then((data) => res.status(status).send(data.payload));
});
export default router;