-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from fac-14/query
Adds DB Queries
- Loading branch information
Showing
10 changed files
with
297 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
// Accepted Challenges | ||
|
||
// Adds the accepted challenges id, the users id and the status for accepted(1) to the table challenge_status | ||
|
||
const db = require('../../db/db_connection'); | ||
|
||
const acceptChallenge = (id, userId) => new Promise((resolve, reject) => { | ||
db.query(`INSERT INTO challenge_status(user_id, challenge_id, status) VALUES ($1, $2, $3)`, [id, userId, 1]) | ||
.then(res => resolve(res)) | ||
.catch(err => reject(err)) | ||
}) | ||
|
||
module.exports = acceptChallenge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
// completeChallenges | ||
// completeChallenges | ||
const db = require('../../db/db_connection'); | ||
|
||
const completeChallenge = (challengeId, userId) => new Promise((resolve, reject) => { | ||
db.query('UPDATE challenge_status SET status = 2 WHERE challenge_id = $1 AND user_id = $2 RETURNING *', [challengeId, userId]) | ||
.then(res => resolve(res)) | ||
.catch(err => reject(err)) | ||
}) | ||
|
||
module.exports = completeChallenge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,64 @@ | ||
|
||
// Gets the users accepted or completed challenges depending on the status code given (1 = accepted and 2 = complete) | ||
|
||
const db = require('../../db/db_connection'); | ||
|
||
const getAccepetedChallenges = (userId, challengeStatus) => new Promise((resolve, reject) => { | ||
db.query(`SELECT * FROM challenges INNER JOIN challenge_status ON challenges.id = challenge_status.challenge_id WHERE user_id = $1 AND status = $2;`, [userId, challengeStatus]) | ||
.then(res => resolve(res)) | ||
.catch(err => reject(err)) | ||
}) | ||
|
||
// 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); | ||
// }); | ||
// }; | ||
|
||
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; | ||
// module.exports = getAcceptedChallenges; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,88 @@ | ||
// 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 | ||
} | ||
]; | ||
// Gets all info for all the challenges | ||
|
||
const db = require('../../db/db_connection'); | ||
|
||
resolve(result); | ||
}); | ||
}; | ||
const getChallenges = () => new Promise((resolve, reject) => { | ||
db.query(`SELECT * FROM challenges;`) | ||
.then(res => resolve(res)) | ||
.catch(err => reject(err)) | ||
}) | ||
|
||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
// 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); | ||
}); | ||
}; | ||
// Gets all the info for a single challenge using the specified id | ||
|
||
const db = require('../../db/db_connection'); | ||
|
||
const getSingleChallenge = (challenge_id) => new Promise((resolve, reject) => { | ||
db.query(`SELECT * FROM challenges WHERE id = $1;`, [challenge_id]) | ||
.then(res => resolve(res)) | ||
.catch(err => reject(err)) | ||
}) | ||
|
||
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; |
Oops, something went wrong.