Skip to content

Commit

Permalink
fixed problems with acceptChallenge and removed dummy data for the ro…
Browse files Browse the repository at this point in the history
…utes

Relates #19 #5
  • Loading branch information
SleepySheepy172 committed Sep 15, 2018
1 parent 4ed0114 commit 3b94b92
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 202 deletions.
1 change: 0 additions & 1 deletion src/controllers/get-accepted-challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const queries = require("../model/index");

exports.get = (req, res) => {
queries.getAcceptedChallenges(1, 1).then(acceptedChallenges => {
console.log("HELLO");
res.render("dashboard", { acceptedChallenges });
});
};
4 changes: 2 additions & 2 deletions src/controllers/get-completed-challenges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const queries = require("../model/index");

exports.get = (req, res) => {
queries.getCompletedChallenges().then(completedChallenges => {
res.render("dashboard", { completedChallenges: completedChallenges });
queries.getCompletedChallenges(1, 2).then(completedChallenges => {
res.render("dashboard", { completedChallenges });
});
};
6 changes: 5 additions & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,24 @@ router.get("/learn", learn.get);
router.get("/stats", userStats.get);
router.get("/inventory-item", itemSelect.get);
router.get("/my-challenge/", acceptedChallSelect.get);

// accepting and completing challenges
router.post("/challenge/accepted", (req, res) => {
// insert query here to add accepted challenge to database
queries.acceptChallenge(0, 1);
queries.acceptChallenge(1, 1);
console.log("Challenge accepted!");
res.redirect(302, "/dashboard");
res.end();
});

router.post("/challenge/completed", (req, res) => {
// insert query here to add completed challenge to database
queries.completeChallenge(1, 1);
console.log("Challenge completed!");
res.redirect(302, "/dashboard");
res.end();
});

if (process.env.NODE_ENV === "test") {
router.get("/make-error", errorRoute);
}
Expand Down
10 changes: 2 additions & 8 deletions src/model/acceptChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const db = require('../../db/db_connection');

const acceptChallenge = (challengeId, userId) => new Promise((resolve, reject) => {
db.query(`INSERT INTO challenge_status (challenge_id, user_id, status) VALUES ($1, $2, $3);`, [challengeId, userId, 1])
.then(res => {
// console.log("hi" + res);
resolve(res)
})
.catch(err => {
// console.log("h");
reject(err)
})
.then(res => resolve(res))
.catch(err => reject(err))
})

module.exports = acceptChallenge;
2 changes: 2 additions & 0 deletions src/model/completeChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const completeChallenge = (challengeId, userId) => new Promise((resolve, reject)
.catch(err => reject(err))
})

// add a query to take reward_points from the challenge and add them to the users points

module.exports = completeChallenge;
50 changes: 0 additions & 50 deletions src/model/getAcceptedChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,3 @@ const getAccepetedChallenges = (userId, challengeStatus) => new Promise((resolve
// should work for accepted and completed challenges just change challengeStatus

module.exports = getAccepetedChallenges;

// DUMMY CODE!!!!!!
// const getAcceptedChallenges = () => {
// return new Promise((resolve, reject) => {
// const result = [
// {
// id: 1,
// inventory_id: 2,
// title: "Go to a farmers market",
// what: "Go to a farmers market",
// why: "you can find organic produces and save packaging waste",
// ext_link: "https://www.lfm.org.uk/",
// img_link:
// "https://s3.eu-central-1.amazonaws.com/lfm-web-prod/images/2016_May_Balham_Herbal_Haven_herbs.0f37de8c.fill-360x360.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Credential=AKIAJXL7S33WNUYF726A%2F20180912%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20180912T140221Z&X-Amz-Signature=3683277a9cc390d6d2d38d8bbad863a38bf16da79f3049a897ac8dad46078746",
// reward_points: 10,
// repeatable: false
// },
// {
// id: 2,
// inventory_id: null,
// title: "Dont buy plastic water bottles for a week",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// },
// {
// id: 3,
// inventory_id: null,
// title: "Stop trashing you dick",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// }
// ];

// resolve(result);
// });
// };

// module.exports = getAcceptedChallenges;
76 changes: 0 additions & 76 deletions src/model/getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,3 @@ const getChallenges = () => new Promise((resolve, reject) => {
})

module.exports = getChallenges;

// DUMMY CODE!!!!!!
// const getChallenges = () => {
// return new Promise((resolve, reject) => {
// const result = [
// {
// id: 1,
// inventory_id: 2,
// title: "Go to a farmers market",
// what: "Go to a farmers market",
// why: "you can find organic produces and save packaging waste",
// ext_link: "https://www.lfm.org.uk/",
// img_link:
// "https://s3.eu-central-1.amazonaws.com/lfm-web-prod/images/2016_May_Balham_Herbal_Haven_herbs.0f37de8c.fill-360x360.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Credential=AKIAJXL7S33WNUYF726A%2F20180912%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20180912T140221Z&X-Amz-Signature=3683277a9cc390d6d2d38d8bbad863a38bf16da79f3049a897ac8dad46078746",
// reward_points: 10,
// repeatable: false
// },
// {
// id: 2,
// inventory_id: null,
// title: "Dont buy plastic water bottles for a week",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// },
// {
// id: 3,
// inventory_id: null,
// title: "Stop trashing you dick",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// },
// {
// id: 4,
// inventory_id: null,
// title: "Get a reusable coffee cup",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// },
// {
// id: 5,
// inventory_id: null,
// title: "Something else importat",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// }
// ];

// resolve(result);
// });
// };

// module.exports = getChallenges;
36 changes: 0 additions & 36 deletions src/model/getCompletedChallenges.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/model/getSingleChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,3 @@ const getSingleChallenge = (challenge_id) => new Promise((resolve, reject) => {
})

module.exports = getSingleChallenge;

// DUMMY CODE!!!!!!

// const getSingleChallenge = () => {
// return new Promise((resolve, reject) => {
// const result = [
// {
// id: 5,
// inventory_id: null,
// title: "Something else importat",
// what: "maybe buy refillable bottle",
// why: "saving lots of plastic",
// ext_link:
// "https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html",
// img_link:
// "https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg",
// reward_points: 10,
// repeatable: true
// }
// ];

// resolve(result);
// });
// };

// module.exports = getSingleChallenge;
4 changes: 2 additions & 2 deletions src/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const acceptChallenge = require('./acceptChallenge')
const completeChallenge = require('./completeChallenge')
const getAcceptedChallenges = require('./getAcceptedChallenges')
const getChallenges = require('./getChallenges')
const getCompletedChallenges = require('./getCompletedChallenges')
// const getCompletedChallenges = require('./getCompletedChallenges')
const getSingleChallenge = require('./getSingleChallenge')

module.exports = {
acceptChallenge,
completeChallenge,
getAcceptedChallenges,
getChallenges,
getCompletedChallenges,
// getCompletedChallenges,
getSingleChallenge
}

0 comments on commit 3b94b92

Please sign in to comment.