Skip to content

Commit

Permalink
added functionality for new card addition
Browse files Browse the repository at this point in the history
Relates #12
xIrusux committed Aug 23, 2019
1 parent dca1c08 commit 41ace1c
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -4,9 +4,12 @@ const favicon = require("serve-favicon");
const exphbs = require("express-handlebars");
const controllers = require("./controllers/index");
const helpers = require("./views/helpers/index");

const bodyparse = require('body-parser');
const app = express();

// post handler
app.use(bodyparse.urlencoded({ extended: false }));

// set up view engine
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
@@ -26,4 +29,6 @@ app.set("port", process.env.PORT || 3000);
app.use(express.static(path.join(__dirname, "..", "public")));
app.use(controllers);



module.exports = app;
1 change: 1 addition & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ const newtarot = require('./newtarot');
router.get('/', home.get);
router.get('/tarot', tarot.tarot);
router.get('/newtarot', newtarot.newtarot);
router.post('/newtarot', newtarot.newtarotpost)
router.use(error.client);
router.use(error.server);

13 changes: 12 additions & 1 deletion src/controllers/newtarot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
const postNewCard = require("../model/database/queries/postNewCard")

exports.newtarot = (req, res) => {
res.render("newtarot")
}
}

exports.newtarotpost = (req, res) => {
postNewCard.postNewCard(req.body["tarot-title"], req.body["tarot-description"])
.then(result => {
console.log({ result });
res.render("newtarot");
})
}

8 changes: 8 additions & 0 deletions src/model/database/queries/postNewCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const connection = require("../db_connection");

exports.postNewCard = (tarottitle, tarotdescription) => {
return connection.query("INSERT INTO tarot_cards (tarot_heading, tarot_description, tarot_image) VALUES($1,$2,$3)",
[tarottitle, tarotdescription, "<svg></svg>"]
)
}

0 comments on commit 41ace1c

Please sign in to comment.