Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create database queries in the challenge models #19

Open
6 of 8 tasks
thejoefriel opened this issue Sep 11, 2018 · 1 comment
Open
6 of 8 tasks

Create database queries in the challenge models #19

thejoefriel opened this issue Sep 11, 2018 · 1 comment

Comments

@thejoefriel
Copy link
Collaborator

thejoefriel commented Sep 11, 2018

  • Get challenge details (we may be able to create one model which gets all the challenge details and then we can just select which bits we want for the challenges landing page and the selected challenge page)
  • Insert accepted challenge
  • Change accepted challenge to completed and add points to user
  • Remove accepted challenge
  • Only get accepted challenges
  • Only get completed challenges
  • Remove completed challenge and remove points from user

Group them together:

  • Set up index.js that requires and then exports all the models from one place
@thejoefriel thejoefriel added this to the Basic app set up milestone Sep 11, 2018
@thejoefriel thejoefriel changed the title Create initial database queries for the challenge models Create database queries in the challenge models Sep 11, 2018
@thejoefriel
Copy link
Collaborator Author

Trying out some pseudo(ish) code for the SQL queries:

Get challenge details:

  • SELECT * FROM challenges

Insert accepted challenge:

  • SELECT id FROM challenges WHERE challenge_name='${challengeName}'
    (the challengeName will be the challenge title name that we need to send across with the POST
  • assign this query to a variable (e.g. sql_getChallengeID)
  • SELECT id FROM users WHERE id = '${userID}'
    (userID will be the user's ID which we need to store during their session and send with the POST or we match against username instead)
  • assign this query to a variable (e.g. sql_getUserID)
  • INSERT INTO challenges-status (user_id, challenge_id, status) VALUES ('${sql_getUserID}', '${sql_getChallengeID}', 'accepted')

Change challenge to completed:

  • SELECT id FROM challenges WHERE challenge_name='${challengeName}'
    (the challengeName will be the challenge title name that we need to send across with the POST)
  • assign this query to a variable (e.g. sql_getChallengeID)
  • SELECT id FROM users WHERE id = '${userID}'
    (userID will be the user's ID which we need to store during their session and send with the POST or we match against username instead)
  • assign this query to a variable (e.g. sql_getUserID)
  • UPDATE challenges-status SET status = completed WHERE challenge_id = $'{sql_getChallengeID)}' AND user_id = '${sql_getUserID}'

Armand-Lluka added a commit that referenced this issue Sep 13, 2018
Armand-Lluka added a commit that referenced this issue Sep 13, 2018
relates to #19
Armand-Lluka added a commit that referenced this issue Sep 13, 2018
Armand-Lluka added a commit that referenced this issue Sep 18, 2018
Armand-Lluka added a commit that referenced this issue Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant