Skip to content

Commit

Permalink
Set up backend template for workshop two. Created example router. Rem…
Browse files Browse the repository at this point in the history
…oved annoying EOL prettier error.
  • Loading branch information
Aokijiop committed Nov 10, 2024
1 parent 610fe44 commit 724efe4
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"ecmaVersion": 13,
"sourceType": "module"
},
"rules": {
}
"rules": { "camelcase": "warn", "prettier/prettier": ["error", { "endOfLine": "auto" }] }
}
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"proseWrap": "always",
"trailingComma": "all",
"semi": true,
"endOfLine": "auto"
}
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const express = require('express');
const cors = require('cors');

// Example of how to import your created routers into app.js
const uselessRouter = require('./routes/uselessRouter');

require('dotenv').config();

const app = express();
Expand All @@ -13,6 +16,9 @@ app.use(
}),
);

// Use your routers here (e.g. app.use('/useless', uselessRouter);)
app.use('/useless', uselessRouter);

app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.17.3",
"nodemon": "^2.0.14",
"pg": "^8.13.1",
"prettier": "^2.4.1"
},
"devDependencies": {
"eslint-config-prettier": "^8.3.0",
"lint-staged": "^11.2.6",
"lint-staged": "^11.2.6",
"husky": "^7.0.4"
"husky": "^7.0.4",
"lint-staged": "^11.2.6"
}
}
2 changes: 1 addition & 1 deletion routes/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Blank file
Create your routers as new files in this directory
22 changes: 22 additions & 0 deletions routes/uselessRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* 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('/', async (req, res) => {
try {
const events = await pool.query('SELECT * FROM theories;');
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;
15 changes: 15 additions & 0 deletions server/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require('dotenv').config();
const { Pool } = require('pg');

const pool = new Pool({
user: process.env.AWS_USER,
password: process.env.AWS_PASSWORD,
host: process.env.AWS_HOST,
port: process.env.AWS_PORT,
database: process.env.AWS_DB_NAME,
ssl: {
rejectUnauthorized: false,
},
});

module.exports = pool;
7 changes: 7 additions & 0 deletions server/schema/believability.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE believability (
id SERIAL PRIMARY KEY, -- Unique identifier for each believability rating
theory_id INT NOT NULL, -- Foreign key referencing the associated theory
user VARCHAR(100) NOT NULL, -- Name of the user giving the rating
believability_score INT CHECK (believability_score >= 1 AND believability_score <= 10), -- Believability score (1-10 scale)
FOREIGN KEY (theory_id) REFERENCES theories(theory_id) ON DELETE CASCADE
);
6 changes: 6 additions & 0 deletions server/schema/evidence.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE evidence (
id SERIAL PRIMARY KEY, -- Unique identifier for each piece of evidence
theory_id INT NOT NULL, -- Foreign key referencing the associated theory
evidence_text TEXT NOT NULL, -- Description of the evidence for the theory
FOREIGN KEY (theory_id) REFERENCES theories(theory_id) ON DELETE CASCADE
);
5 changes: 5 additions & 0 deletions server/schema/theories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE theories (
id SERIAL PRIMARY KEY, -- Unique identifier for each theory
title VARCHAR(255) NOT NULL, -- Title of the theory, e.g., "The Moon Landing Was Faked"
description TEXT NOT NULL -- Description providing details of the theory
);
88 changes: 88 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,62 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

pg-cloudflare@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz#e6d5833015b170e23ae819e8c5d7eaedb472ca98"
integrity sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==

pg-connection-string@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.7.0.tgz#f1d3489e427c62ece022dba98d5262efcb168b37"
integrity sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==

pg-pool@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.7.0.tgz#d4d3c7ad640f8c6a2245adc369bafde4ebb8cbec"
integrity sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==

pg-protocol@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.7.0.tgz#ec037c87c20515372692edac8b63cf4405448a93"
integrity sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==

pg-types@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3"
integrity sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==
dependencies:
pg-int8 "1.0.1"
postgres-array "~2.0.0"
postgres-bytea "~1.0.0"
postgres-date "~1.0.4"
postgres-interval "^1.1.0"

pg@^8.13.1:
version "8.13.1"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.13.1.tgz#6498d8b0a87ff76c2df7a32160309d3168c0c080"
integrity sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ==
dependencies:
pg-connection-string "^2.7.0"
pg-pool "^3.7.0"
pg-protocol "^1.7.0"
pg-types "^2.1.0"
pgpass "1.x"
optionalDependencies:
pg-cloudflare "^1.1.1"

[email protected]:
version "1.0.5"
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d"
integrity sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==
dependencies:
split2 "^4.1.0"

picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
Expand All @@ -1883,6 +1939,28 @@ please-upgrade-node@^3.2.0:
dependencies:
semver-compare "^1.0.0"

postgres-array@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==

postgres-bytea@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
integrity sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==

postgres-date@~1.0.4:
version "1.0.7"
resolved "https://registry.yarnpkg.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==

postgres-interval@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
integrity sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==
dependencies:
xtend "^4.0.0"

prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
Expand Down Expand Up @@ -2158,6 +2236,11 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

split2@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/split2/-/split2-4.2.0.tgz#c9c5920904d148bab0b9f67145f245a86aadbfa4"
integrity sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
Expand Down Expand Up @@ -2480,6 +2563,11 @@ xdg-basedir@^4.0.0:
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==

xtend@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
Expand Down

0 comments on commit 724efe4

Please sign in to comment.