-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from fac19/backend-files
add backend files and folders
- Loading branch information
Showing
16 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const db = require("./connection"); | ||
|
||
const initPath = path.join(__dirname, "init.sql"); | ||
const initSQL = fs.readFileSync(initPath, "utf-8"); | ||
|
||
function build (){ | ||
return db.query(initSQL); | ||
} | ||
|
||
module.exports = build; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const pg = require("pg"); | ||
const dotenv = require("dotenv"); | ||
|
||
dotenv.config(); | ||
|
||
const db = new pg.Pool({ | ||
connectionString: process.env.DATABASE_URL, | ||
// if we have a database URL (e.g. from Heroku we'll use that) | ||
// otherwise it'll default to your local .env variables | ||
}); | ||
|
||
module.exports = db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
BEGIN; | ||
|
||
DROP TABLE IF EXISTS users, posts; | ||
|
||
CREATE TABLE users( | ||
-- id SERIAL PRIMARY KEY UNIQUE, | ||
-- username VARCHAR(255) NOT NULL UNIQUE, | ||
-- email VARCHAR(255) NOT NULL UNIQUE, | ||
-- password VARCHAR(255) | ||
); | ||
|
||
CREATE TABLE posts( | ||
-- id SERIAL PRIMARY KEY, | ||
-- user_id INTEGER REFERENCES users(id), | ||
-- category VARCHAR(255) NOT NULL, | ||
-- tool_name VARCHAR(255), | ||
-- tool_description VARCHAR(255), | ||
-- tool_link VARCHAR(255) | ||
); | ||
|
||
INSERT INTO users (username, email, password) VALUES () | ||
|
||
|
||
INSERT INTO categories (category) VALUES () | ||
|
||
|
||
INSERT INTO posts (user_id, cat_id, tool_name, tool_description, tool_link, date_added) VALUES | ||
(1,3, 'Netflix', 'Stream shows and movies', 'netflix.com', '2019-08-01'), | ||
|
||
|
||
END; |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function logger(req, res, next) { | ||
const time = new Date().toLocaleTimeString(); | ||
console.log(`${time} ${req.method} ${req.url}`); | ||
next(); | ||
} | ||
|
||
module.exports = logger; | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const express = require("express"); | ||
const auth = require("../middleware/auth"); | ||
const error = require("../middleware/error"); | ||
const logger = require('./middleware/logger'); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
const server = express(); | ||
server.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`)); | ||
|
||
server.use(express.json()); //so that express knows to use JSON | ||
const logger = require('./middleware/logger') | ||
|
||
//Routes for users | ||
|
||
|
||
//Routes for projects | ||
|
||
|
||
//Routes for comments | ||
|
||
|
||
//Error handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const test = require('tape') | ||
const build = require('../database/build') | ||
const model = require('../model') | ||
|
||
test('Test to see if this runs', t => { | ||
t.equal(1 + 1, 2, '1+1 should equal 2') | ||
t.end() | ||
}) | ||
|
||
test('Check model is exporting getAllUsers function', t => { | ||
build() | ||
.then(() => { | ||
t.equal('getAllUsers' in model, true) | ||
t.end() | ||
}) | ||
.catch(error => { | ||
t.error(error) | ||
t.end() | ||
}) | ||
}) |
Empty file.