diff --git a/README.md b/README.md index 810bdf2..6425f13 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/db/db_connection.js b/db/db_connection.js index d6ea3de..003a4f0 100644 --- a/db/db_connection.js +++ b/db/db_connection.js @@ -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); diff --git a/db/test_build.js b/db/test_build.js index 7dadadd..4f5babd 100644 --- a/db/test_build.js +++ b/db/test_build.js @@ -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; \ No newline at end of file +module.exports = initialiseTestDatabase; diff --git a/public/css/style.css b/public/css/main.css similarity index 100% rename from public/css/style.css rename to public/css/main.css diff --git a/public/css/navbar.css b/public/css/navbar.css new file mode 100644 index 0000000..44edfde --- /dev/null +++ b/public/css/navbar.css @@ -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; +} \ No newline at end of file diff --git a/public/imgs/Avatar.png b/public/imgs/Avatar.png new file mode 100644 index 0000000..efcde9d Binary files /dev/null and b/public/imgs/Avatar.png differ diff --git a/src/controllers/challSelect.js b/src/controllers/challSelect.js index 093de5e..1c5b881 100644 --- a/src/controllers/challSelect.js +++ b/src/controllers/challSelect.js @@ -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] + }); + }); }; diff --git a/src/controllers/dashboard.js b/src/controllers/dashboard.js index 2007fad..61ebadc 100644 --- a/src/controllers/dashboard.js +++ b/src/controllers/dashboard.js @@ -1,3 +1,17 @@ +const queries = require("../model/index"); + exports.get = (req, res) => { - res.render("dashboard"); -}; \ No newline at end of file + + 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] + }); + }) +}; diff --git a/src/controllers/get-accepted-challenges.js b/src/controllers/get-accepted-challenges.js new file mode 100644 index 0000000..0d78a41 --- /dev/null +++ b/src/controllers/get-accepted-challenges.js @@ -0,0 +1,7 @@ +const queries = require("../model/index"); + +exports.get = (req, res) => { + queries.getAcceptedChallenges().then(acceptedChallenges => { + res.render("dashboard", { acceptedChallenges: acceptedChallenges }); + }); +}; diff --git a/src/controllers/get-completed-challenges.js b/src/controllers/get-completed-challenges.js new file mode 100644 index 0000000..b6e18f7 --- /dev/null +++ b/src/controllers/get-completed-challenges.js @@ -0,0 +1,7 @@ +const queries = require("../model/index"); + +exports.get = (req, res) => { + queries.getCompletedChallenges().then(completedChallenges => { + res.render("dashboard", { completedChallenges: completedChallenges }); + }); +}; diff --git a/src/controllers/index.js b/src/controllers/index.js index 055d764..9e9d306 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -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); @@ -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); diff --git a/src/model/getAcceptedChallenges.js b/src/model/getAcceptedChallenges.js index 7c89e46..622f345 100644 --- a/src/model/getAcceptedChallenges.js +++ b/src/model/getAcceptedChallenges.js @@ -11,4 +11,54 @@ const getAccepetedChallenges = (userId, challengeStatus) => new Promise((resolve // should work for accepted and completed challenges just change challengeStatus -module.exports = getAccepetedChallenges; \ No newline at end of file +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; diff --git a/src/model/getChallenges.js b/src/model/getChallenges.js index 97d37d4..5cbc907 100644 --- a/src/model/getChallenges.js +++ b/src/model/getChallenges.js @@ -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; \ No newline at end of file +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; diff --git a/src/model/getCompletedChallenges.js b/src/model/getCompletedChallenges.js index a37aaa4..1c19b9e 100644 --- a/src/model/getCompletedChallenges.js +++ b/src/model/getCompletedChallenges.js @@ -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; diff --git a/src/model/getSingleChallenge.js b/src/model/getSingleChallenge.js index a2f4101..c9f77f7 100644 --- a/src/model/getSingleChallenge.js +++ b/src/model/getSingleChallenge.js @@ -9,4 +9,30 @@ const getSingleChallenge = (challenge_id) => new Promise((resolve, reject) => { .catch(err => reject(err)) }) -module.exports = getSingleChallenge; \ No newline at end of file +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; diff --git a/src/model/index.js b/src/model/index.js index 5e6213d..49f0b21 100644 --- a/src/model/index.js +++ b/src/model/index.js @@ -13,4 +13,4 @@ module.exports = { getChallenges, getCompletedChallenges, getSingleChallenge -} \ No newline at end of file +} diff --git a/src/views/challSelect.hbs b/src/views/challSelect.hbs index b2d1f42..59c1b21 100644 --- a/src/views/challSelect.hbs +++ b/src/views/challSelect.hbs @@ -1,8 +1,32 @@ -{{!-- hello again --}} -

this is the selected challenge

-
-

Accept challenge?

- -
\ No newline at end of file +
+ + + +

{{{challenge.title}}}

+ +
+

What

+

+ {{{challenge.what}}} +

+
+ +
+

Why

+

+ {{{challenge.why}}} +

+
+ + + +
+

Accept challenge?

+ +
+ + + +
\ No newline at end of file diff --git a/src/views/dashboard.hbs b/src/views/dashboard.hbs index ae33c89..f5d554d 100644 --- a/src/views/dashboard.hbs +++ b/src/views/dashboard.hbs @@ -1,9 +1,52 @@

This is home dashboard where user can see their challenges

- \ No newline at end of file +
+
+

New Challenges

+
+
+ {{#each newChallenges}} +
+ +

{{this.title}}

+ + {{/each}} +
+ +
+ +
+
+

Accepted Challenges

+
+
+ {{#each acceptedChallenges}} +
+ +

{{this.title}}

+ + {{/each}} +
+ +
+ +
+
+

Completed Challenges

+
+
+ {{#each completedChallenges}} +
+ +

{{this.title}}

+ + {{/each}} +
+ +
\ No newline at end of file diff --git a/src/views/partials/footer.hbs b/src/views/partials/footer.hbs index b9045bc..63b88ac 100644 --- a/src/views/partials/footer.hbs +++ b/src/views/partials/footer.hbs @@ -1,4 +1,6 @@ {{!-- think this is where footers and stuff go? --}} \ No newline at end of file diff --git a/src/views/partials/header.hbs b/src/views/partials/header.hbs index 7cb708a..8953cea 100644 --- a/src/views/partials/header.hbs +++ b/src/views/partials/header.hbs @@ -4,5 +4,6 @@ ZeroWaste + diff --git a/src/views/partials/navbar.hbs b/src/views/partials/navbar.hbs index 2337b6d..6988900 100644 --- a/src/views/partials/navbar.hbs +++ b/src/views/partials/navbar.hbs @@ -1,5 +1,12 @@
\ No newline at end of file diff --git a/test/routes.test.js b/test/routes.test.js index d694bbe..1f7aca3 100644 --- a/test/routes.test.js +++ b/test/routes.test.js @@ -28,7 +28,7 @@ describe("Test the dashboard page", () => { describe("Test the challSelect page", () => { test("Expecting a 200 status return", done => { supertest(app) - .get("/challenge/") + .get("/challenges/:challenges/") .then(response => { expect(response.statusCode).toBe(200); done();