Skip to content

Commit

Permalink
readme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GainorB committed Aug 3, 2017
1 parent f1ddfc4 commit 7e67db7
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 118 deletions.
64 changes: 61 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
node_modules
.DS_Store
.env
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


.DS_Store
8 changes: 7 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
const promise = require('bluebird');

// OVERRIDING DEFAULT PROMISE LIBRARY
const options = { promiseLib: promise };
// WHENEVER THERE IS A DATABASE INTERACTION WITH A ROUTE, THE DB QUERY WILL CONSOLE LOG
const options = {
promiseLib: promise,
query: (e) => {
console.log(e.query);
}
};
const pgp = require('pg-promise')(options);

// SET UP THE CONNECTION STRING FOR THE DATABASE
Expand Down
8 changes: 4 additions & 4 deletions config/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS articles(
content TEXT NOT NULL
);

INSERT into articles(title, content) VALUES('Article 1', 'This is article 1');
INSERT into articles(title, content) VALUES('Article 2', 'This is article 2');
INSERT into articles(title, content) VALUES('Article 3', 'This is article 3');
INSERT into articles(title, content) VALUES('Article 4', 'This is article 4');
-- INSERT into articles(title, content) VALUES('Article 1', 'This is article 1');
-- INSERT into articles(title, content) VALUES('Article 2', 'This is article 2');
-- INSERT into articles(title, content) VALUES('Article 3', 'This is article 3');
-- INSERT into articles(title, content) VALUES('Article 4', 'This is article 4');
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,47 @@ const express = require('express');
const router = express.Router();

// REQUIRE MODEL
const index = require('../models/index.js');
const Article = require('../models/article.js');

// GET ALL ARTICLES
router.get('/', (req, res, next) => {
index.getAllArticles()
Article.get()
//.then(data => console.log(data))
//.then(data => res.render('index', { data }))
.then(data => res.json({ title: 'Retreived all Articles', success: true, data }))
.catch(err => res.json({ err }));
});

// CREATE ARTICLE
router.post('/newArticle', (req, res, next) => {
router.post('/new', (req, res, next) => {
// USE BODY PARSER TO EXTRACT DATA FROM CLIENT
const { title, content } = req.body;
index.createArticle(title, content)

Article.create(title, content)
.then(res.json({ success: true, msg: 'Article Created' }))
.catch(err => res.json({ err }));
});

// UPDATE ARTICLE
router.put('/updateArticle/:id', (req, res, next) => {
router.put('/update/article/:id', (req, res, next) => {
// USE BODY PARSER TO EXTRACT DATA FROM CLIENT
const { title, content } = req.body;
// ID OF ARTICLE TO UPDATE
let id = req.params.id;

index.updateArticle(req.body.title, req.body.content, id)
Article.update(title, content, id)
.then(res.json({ success: true, msg: 'Article Updated' }))
.catch(err => res.json({ err }));
});

// DELETE ARTICLE
router.delete('/deleteArticle/:id', (req, res, next) => {
router.delete('/delete/article/:id', (req, res, next) => {
let id = req.params.id;

index.deleteArticle(id)
Article.delete(id)
.then(res.json({ success: true, msg: 'Article Deleted' }))
.catch(err => res.json({ err }));
});



module.exports = router;
27 changes: 27 additions & 0 deletions models/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const db = require('../config/config');

// EMPTY OBJECT
// USED FOR EXPORTING THE FUNCTIONS BELOW
const Article = {};

// CREATE ARTICLE
Article.create = (title, content) => {
return db.none(`INSERT into articles(title, content)` + `VALUES($1, $2)`, [title, content]);
}

// GET ALL ARTICLES
Article.get = () => {
return db.any('SELECT * FROM articles');
}

// UPDATE AN ARTICLE
Article.update = (title, content, articleID) => {
return db.none(`UPDATE articles SET title = $1, content = $2 WHERE id = $3`, [title, content, articleID]);
}

// DELETE AN ARTICLE
Article.delete = articleID => {
return db.none(`DELETE from articles WHERE id = $1`, articleID);
}

module.exports = Article;
29 changes: 0 additions & 29 deletions models/index.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"bluebird": "^3.5.0",
"body-parser": "^1.17.2",
"cors": "^2.8.4",
"dotenv": "^4.0.0",
"ejs": "^2.5.6",
"express": "^4.15.3",
Expand All @@ -21,4 +20,4 @@
"nodemon": "^1.11.0",
"morgan": "^1.8.2"
}
}
}
Binary file modified readme-assets/mvc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7e67db7

Please sign in to comment.