Skip to content

Commit

Permalink
Add psql database with schema and saveRepo in model.js
Browse files Browse the repository at this point in the history
Relates #8
  • Loading branch information
tacotoemeck committed Apr 5, 2020
1 parent cafc812 commit 2644ace
Show file tree
Hide file tree
Showing 201 changed files with 18,946 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL = project_board_test
PGUSER=project_board_test_user
PGPASSWORD=1234
Empty file added db/build.js
Empty file.
8 changes: 8 additions & 0 deletions db/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const pg = require("pg");
const dotenv = require("dotenv");

dotenv.config();

const db = new pg.Pool({ connectionString: process.env.DATABASE_URL });

module.exports = db;
22 changes: 22 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BEGIN;

DROP TABLE IF EXISTS projects, users
CASCADE;

CREATE TABLE users
(
id SERIAL PRIMARY KEY,
github_link VARCHAR(255) NOT NULL,
github_img VARCHAR(255) NOT NULL
);

CREATE TABLE projects
(
id SERIAL PRIMARY KEY,
project_name VARCHAR(255) NOT NULL,
project_screenshot VARCHAR(255) ,
project_link VARCHAR(255) ,
collaborators INTEGER REFERENCES users(id)
);

COMMIT;
29 changes: 15 additions & 14 deletions handlers/submitPost.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const templates = require("../templates/templates");
const model = require("../model");

function submitPostHandler(req, res) {
// let body = "";
// req.on("data", (chunk) => (body += chunk));
// req.on("end", () => {
// const message = new URLSearchParams(body);
// const messageObject = Object.fromEntries(message);
// model
// .newPost(messageObject)
// .then(() => {
// res.writeHead(302, { location: "/" });
// res.end();
// })
// .catch((err) => console.error(err));
// });
let body = "";
req.on("data", (chunk) => (body += chunk));
req.on("end", () => {
const repo = new URLSearchParams(body);
const repoObject = Object.fromEntries(repo);
console.log(repoObject);
model
.saveRepo(repoObject)
.then(() => {
res.writeHead(302, { location: "/" });
res.end();
})
.catch((err) => console.error(err));
});
}

module.exports = submitPostHandler;
10 changes: 10 additions & 0 deletions model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const db = require("./db/connection");

function saveRepo(repo) {
console.log(repo.project_name);
return db.query("INSERT INTO projects(project_name) VALUES($1)", [
repo.project_name,
]);
}

module.exports = { saveRepo };
7 changes: 7 additions & 0 deletions node_modules/buffer-writer/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions node_modules/buffer-writer/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions node_modules/buffer-writer/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions node_modules/buffer-writer/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions node_modules/buffer-writer/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/buffer-writer/test/mocha.opts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2644ace

Please sign in to comment.