Skip to content

Commit

Permalink
fixed merge conflicts in DB queries
Browse files Browse the repository at this point in the history
  • Loading branch information
SleepySheepy172 committed Sep 14, 2018
2 parents e22f412 + 219daf0 commit 2f3ea68
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 69 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.com/fac-14/race-to-zero.svg?branch=master)](https://travis-ci.com/fac-14/race-to-zero) [![codecov](https://codecov.io/gh/fac-14/race-to-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/fac-14/race-to-zero)

## Overview

### Description
Expand Down
27 changes: 0 additions & 27 deletions db/db_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,3 @@ const connection =
const db = pgp(connection);

module.exports = db;

// const { Pool } = require('pg');
// const url = require('url');
// const env = require('env2');
// env('./config.env');
// let DB_URL = process.env.DATABASE_URL;

// if (process.env.NODE_ENV === 'test') {
// DB_URL = process.env.TEST_DB_URL;
// }

// if (!DB_URL) throw new Error("Environment vatialbe must be set");

// const params = url.parse(DB_URL);
// const [username, password] = params.auth.split(":");

// const options = {
// host: params.hostname,
// port: params.port,
// database: params.pathname.split("/")[1],
// max: process.env.DB_MAX_CONNECTIONS || 2,
// user: username,
// password,
// ssl: params.hostname !== "localhost"
// };

// module.exports = new Pool(options);
17 changes: 3 additions & 14 deletions db/test_build.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
// go tests
const fs = require('fs');
const dbConnection = require('./db_connection');
const fs = require("fs");
const dbConnection = require("./db_connection");

const sql = fs.readFileSync(`${__dirname}/test_build.sql`).toString();

const initialiseTestDatabase = () => dbConnection.query(sql);

// const runDbTestBuild = () =>
// new Promise((resolve, reject) => {
// dbConnection.query(sql, (err, result) => {
// if (err) {
// reject(err);
// } else {
// resolve(result);
// }
// });
// });

module.exports = initialiseTestDatabase;
module.exports = initialiseTestDatabase;
File renamed without changes.
37 changes: 37 additions & 0 deletions public/css/navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
nav{
display: flex;
width: 100vw;
}

#xp-section{
background-color: aqua;
display: flex;
flex-direction: row;
width: 70vw;
height: 3rem;
align-items: center;
justify-content: flex-start;
}

progress[value] {
/* Reset the default appearance */
-webkit-appearance: none;
appearance: none;
}

#xp-bar{
width: 50vw;
height: 20px;
}

#avatar-section{
background-color: aquamarine;
}

h3{
margin: 1rem;
}

#profile-pic{
width: 8rem;
}
Binary file added public/imgs/Avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/controllers/challSelect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const queries = require("../model/index");

exports.get = (req, res) => {
res.render("challSelect", { layout: "content-selected" });
queries.getSingleChallenge().then(challengeDetails => {
console.log("challenge details: ", challengeDetails);
res.render("challSelect", {
layout: "content-selected",
challenge: challengeDetails[0]
});
});
};
18 changes: 16 additions & 2 deletions src/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
const queries = require("../model/index");

exports.get = (req, res) => {
res.render("dashboard");
};

const newChallenges = queries.getChallenges();
const acceptedChallenges = queries.getAcceptedChallenges();
const completedChallenges = queries.getCompletedChallenges();

Promise.all([newChallenges, acceptedChallenges, completedChallenges])
.then(challenges => {
res.render("dashboard", {
newChallenges: challenges[0],
acceptedChallenges: challenges[1],
completedChallenges: challenges[2]
});
})
};
7 changes: 7 additions & 0 deletions src/controllers/get-accepted-challenges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const queries = require("../model/index");

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

exports.get = (req, res) => {
queries.getCompletedChallenges().then(completedChallenges => {
res.render("dashboard", { completedChallenges: completedChallenges });
});
};
4 changes: 2 additions & 2 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ router.get("/", landing.get);
// router.get("login", login.get);
// router.post("login", login.post);
router.get("/dashboard", dashboard.get);
router.get("/challenge", challSelect.get);
router.get("/challenges/:challenges", challSelect.get);
router.get("/inventory", inventory.get);
router.get("/make-error", errorRoute);
router.get("/learn", learn.get);
Expand All @@ -43,7 +43,7 @@ router.post("/challenge/completed", (req, res) => {
res.end();
});
if (process.env.NODE_ENV === "test") {
router.get("/make-error", errorRoute);
router.get("/make-error", errorRoute);
}
router.use(error.client);
// router.use(error.server);
Expand Down
52 changes: 51 additions & 1 deletion src/model/getAcceptedChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,54 @@ const getAccepetedChallenges = (userId, challengeStatus) => new Promise((resolve

// should work for accepted and completed challenges just change challengeStatus

module.exports = getAccepetedChallenges;
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;
84 changes: 80 additions & 4 deletions src/model/getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,85 @@
const db = require('../../db/db_connection');

const getChallenges = () => new Promise((resolve, reject) => {
db.query(`SELECT * FROM challenges;`)
.then(res => resolve(res))
.catch(err => reject(err))
db.query(`SELECT * FROM challenges;`)
.then(res => resolve(res))
.catch(err => reject(err))
})

module.exports = getChallenges;
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;
35 changes: 35 additions & 0 deletions src/model/getCompletedChallenges.js
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
// can use getAcceptedChallenges for this so delete later
const getCompletedChallenges = () => {
return new Promise((resolve, reject) => {
const result = [
{
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 = getCompletedChallenges;
28 changes: 27 additions & 1 deletion src/model/getSingleChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,30 @@ const getSingleChallenge = (challenge_id) => new Promise((resolve, reject) => {
.catch(err => reject(err))
})

module.exports = getSingleChallenge;
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;
2 changes: 1 addition & 1 deletion src/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ module.exports = {
getChallenges,
getCompletedChallenges,
getSingleChallenge
}
}
Loading

0 comments on commit 2f3ea68

Please sign in to comment.