-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Relates #8
- Loading branch information
There are no files selected for viewing
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 |
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; |
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; |
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; |
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 }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.