Skip to content

Commit dfd324b

Browse files
committed
finished project
1 parent 4eb1abd commit dfd324b

File tree

7 files changed

+4275
-2579
lines changed

7 files changed

+4275
-2579
lines changed

.yarn/install-state.gz

344 KB
Binary file not shown.

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const cors = require('cors');
33

44
// Example of how to import your created routers into app.js
55
const uselessRouter = require('./routes/uselessRouter');
6+
const theory1router = require('./routes/theory1');
7+
const theory2router = require('./routes/theory2');
8+
const theory3router = require('./routes/theory3');
69

710
require('dotenv').config();
811

@@ -18,6 +21,9 @@ app.use(
1821

1922
// Use your routers here (e.g. app.use('/useless', uselessRouter);)
2023
app.use('/useless', uselessRouter);
24+
app.use('/theory1', theory1router);
25+
app.use('/theory2', theory2router);
26+
app.use('/theory3', theory3router);
2127

2228
app.listen(PORT, () => {
2329
console.log(`Server listening on ${PORT}`);

routes/theory1.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable camelcase */
2+
const express = require('express');
3+
4+
const theory1router = express.Router();
5+
const pool = require('../server/db');
6+
7+
require('dotenv').config();
8+
9+
theory1router.use(express.json());
10+
11+
// Notice how we're using a get (But there's also others like post, put/patch, delete)
12+
theory1router.get('/easy', async (req, res) => {
13+
try {
14+
// SELECT *
15+
// FROM theories
16+
// WHERE title = 'There is a CTC to FAANG pipeline';
17+
const events = await pool.query(
18+
"SELECT * FROM theories WHERE title = 'There is a CTC to FAANG pipeline';",
19+
);
20+
res.status(200).json(events.rows);
21+
} catch (err) {
22+
res.status(500).json(err.message);
23+
}
24+
});
25+
26+
theory1router.get('/medium', async (req, res) => {
27+
try {
28+
const events = await pool.query('SELECT AVG(believability_score) FROM believability;');
29+
res.status(200).json(events.rows);
30+
} catch (err) {
31+
res.status(500).json(err.message);
32+
}
33+
});
34+
35+
theory1router.get('/hard', async (req, res) => {
36+
try {
37+
const events = await pool.query(
38+
"SELECT believability_score FROM believability AS b JOIN theories AS t ON t.id = b.id WHERE t.title = 'There is a CTC to FAANG pipeline';",
39+
);
40+
res.status(200).json(events.rows);
41+
} catch (err) {
42+
res.status(500).json(err.message);
43+
}
44+
});
45+
46+
// IMPORTANT: This is how you export your router in order to make it importable in app.js
47+
module.exports = theory1router;

routes/theory2.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* eslint-disable camelcase */
2+
const express = require('express');
3+
4+
const uselessRouter = express.Router();
5+
const pool = require('../server/db');
6+
7+
require('dotenv').config();
8+
9+
uselessRouter.use(express.json());
10+
11+
// Notice how we're using a get (But there's also others like post, put/patch, delete)
12+
uselessRouter.get('/easy', async (req, res) => {
13+
try {
14+
const events = await pool.query(
15+
'SELECT evidence_text' +
16+
'FROM evidence AS e' +
17+
'JOIN theories AS t ON e.id = t.id' +
18+
"WHERE title = 'Kevin has a crippling league addiction';",
19+
);
20+
res.status(200).json(events.rows);
21+
} catch (err) {
22+
res.status(500).json(err.message);
23+
}
24+
});
25+
uselessRouter.get('/medium', async (req, res) => {
26+
try {
27+
const events = await pool.query(
28+
'SELECT COUNT(evidence_text)' +
29+
'FROM evidence AS e' +
30+
'JOIN theories AS t ON e.id = t.id' +
31+
"WHERE title = 'Kevin has a crippling league addiction';",
32+
);
33+
res.status(200).json(events.rows);
34+
} catch (err) {
35+
res.status(500).json(err.message);
36+
}
37+
});
38+
uselessRouter.get('/hard', async (req, res) => {
39+
try {
40+
const events = await pool.query(
41+
'SELECT MIN(b) FROM (SELECT AVG(believability_score) as b FROM believability);',
42+
);
43+
res.status(200).json(events.rows);
44+
} catch (err) {
45+
res.status(500).json(err.message);
46+
}
47+
});
48+
49+
// IMPORTANT: This is how you export your router in order to make it importable in app.js
50+
module.exports = uselessRouter;

routes/theory3.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable camelcase */
2+
const express = require('express');
3+
4+
const theory1router = express.Router();
5+
const pool = require('../server/db');
6+
7+
require('dotenv').config();
8+
9+
theory1router.use(express.json());
10+
11+
// Notice how we're using a get (But there's also others like post, put/patch, delete)
12+
theory1router.get('/easy', async (req, res) => {
13+
try {
14+
const events = await pool.query(
15+
'SELECT b.submitter FROM believability AS b' +
16+
"JOIN theories AS t ON t.id = b.theory_id WHERE t.title = 'CTC devs will be replaced by AI in the future';",
17+
);
18+
res.status(200).json(events.rows);
19+
} catch (err) {
20+
res.status(500).json(err.message);
21+
}
22+
});
23+
24+
theory1router.get('/medium', async (req, res) => {
25+
try {
26+
const events = await pool.query(
27+
'SELECT b.submitter FROM believability AS b' +
28+
'JOIN theories AS t ON t.id = b.theory_id' +
29+
"WHERE t.title = 'CTC devs will be replaced by AI in the future' AND b.believability_score > 4;",
30+
);
31+
res.status(200).json(events.rows);
32+
} catch (err) {
33+
res.status(500).json(err.message);
34+
}
35+
});
36+
37+
theory1router.get('/hard', async (req, res) => {
38+
try {
39+
const events = await pool.query(
40+
'SELECT AVG(believability_score)' +
41+
'FROM believability' +
42+
'WHERE believability_score > 1 AND believability_score < 10;',
43+
);
44+
res.status(200).json(events.rows);
45+
} catch (err) {
46+
res.status(500).json(err.message);
47+
}
48+
});
49+
50+
// IMPORTANT: This is how you export your router in order to make it importable in app.js
51+
module.exports = theory1router;

0 commit comments

Comments
 (0)