Skip to content

Commit

Permalink
finished project
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenwang0815 committed Nov 10, 2024
1 parent 4eb1abd commit dfd324b
Show file tree
Hide file tree
Showing 7 changed files with 4,275 additions and 2,579 deletions.
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const cors = require('cors');

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

require('dotenv').config();

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

// Use your routers here (e.g. app.use('/useless', uselessRouter);)
app.use('/useless', uselessRouter);
app.use('/theory1', theory1router);
app.use('/theory2', theory2router);
app.use('/theory3', theory3router);

app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
Expand Down
47 changes: 47 additions & 0 deletions routes/theory1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable camelcase */
const express = require('express');

const theory1router = express.Router();
const pool = require('../server/db');

require('dotenv').config();

theory1router.use(express.json());

// Notice how we're using a get (But there's also others like post, put/patch, delete)
theory1router.get('/easy', async (req, res) => {
try {
// SELECT *
// FROM theories
// WHERE title = 'There is a CTC to FAANG pipeline';
const events = await pool.query(
"SELECT * FROM theories WHERE title = 'There is a CTC to FAANG pipeline';",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

theory1router.get('/medium', async (req, res) => {
try {
const events = await pool.query('SELECT AVG(believability_score) FROM believability;');
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

theory1router.get('/hard', async (req, res) => {
try {
const events = await pool.query(
"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';",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

// IMPORTANT: This is how you export your router in order to make it importable in app.js
module.exports = theory1router;
50 changes: 50 additions & 0 deletions routes/theory2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable camelcase */
const express = require('express');

const uselessRouter = express.Router();
const pool = require('../server/db');

require('dotenv').config();

uselessRouter.use(express.json());

// Notice how we're using a get (But there's also others like post, put/patch, delete)
uselessRouter.get('/easy', async (req, res) => {
try {
const events = await pool.query(
'SELECT evidence_text' +
'FROM evidence AS e' +
'JOIN theories AS t ON e.id = t.id' +
"WHERE title = 'Kevin has a crippling league addiction';",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});
uselessRouter.get('/medium', async (req, res) => {
try {
const events = await pool.query(
'SELECT COUNT(evidence_text)' +
'FROM evidence AS e' +
'JOIN theories AS t ON e.id = t.id' +
"WHERE title = 'Kevin has a crippling league addiction';",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});
uselessRouter.get('/hard', async (req, res) => {
try {
const events = await pool.query(
'SELECT MIN(b) FROM (SELECT AVG(believability_score) as b FROM believability);',
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

// IMPORTANT: This is how you export your router in order to make it importable in app.js
module.exports = uselessRouter;
51 changes: 51 additions & 0 deletions routes/theory3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable camelcase */
const express = require('express');

const theory1router = express.Router();
const pool = require('../server/db');

require('dotenv').config();

theory1router.use(express.json());

// Notice how we're using a get (But there's also others like post, put/patch, delete)
theory1router.get('/easy', async (req, res) => {
try {
const events = await pool.query(
'SELECT b.submitter FROM believability AS b' +
"JOIN theories AS t ON t.id = b.theory_id WHERE t.title = 'CTC devs will be replaced by AI in the future';",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

theory1router.get('/medium', async (req, res) => {
try {
const events = await pool.query(
'SELECT b.submitter FROM believability AS b' +
'JOIN theories AS t ON t.id = b.theory_id' +
"WHERE t.title = 'CTC devs will be replaced by AI in the future' AND b.believability_score > 4;",
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

theory1router.get('/hard', async (req, res) => {
try {
const events = await pool.query(
'SELECT AVG(believability_score)' +
'FROM believability' +
'WHERE believability_score > 1 AND believability_score < 10;',
);
res.status(200).json(events.rows);
} catch (err) {
res.status(500).json(err.message);
}
});

// IMPORTANT: This is how you export your router in order to make it importable in app.js
module.exports = theory1router;
Loading

0 comments on commit dfd324b

Please sign in to comment.