Compare commits

...

10 Commits

Author SHA1 Message Date
Prince Mendiratta f5df0442ed
fix: remove .replit file (#67)
Signed-off-by: Prince Mendiratta <prince.mendi@gmail.com>

Signed-off-by: Prince Mendiratta <prince.mendi@gmail.com>
1 year ago
Tom d215349ccf
fix: replit issues (#63)
* fix: replit issues

* test

* test

* chore: package-lock
2 years ago
Kealan Parr 898b12a905
fix: rename server.js to index.js for replit debugging (#60) 2 years ago
Naomi Carrigan b0fdba645f
chore: clarify readme (#61) 2 years ago
Kristofer Koishigawa 55797155b7
fix: sync index.html with demo, update query strings example and favicon (#53)
* fix: remove unnecessary &amp; from query string

* fix: sync with demo project index.html file

* fix: update favicon

* fix: update date input id
3 years ago
gikf 9eb0d63d53
fix: update urls to new version of project (#51)
Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
3 years ago
Nicholas Carrigan (he/him) 045979ab01
fix: Remove engine from package.json (#45)
Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>
3 years ago
Tom e3a0289ea2
fix: remove user stories (#42)
* fix: remove user stories

* fix: remove assets + add sample.env, dotenv, gitignore

* fix: update package-lock

* fix: add dotenv + update package-lock

* feat: remove error handling

* fix: remove mlab env var

* fix: remove bashrc

* remove express body parser + organize code

* fix: remove gitconfig
4 years ago
Artur J Zapater bc38f78803
updated dependencies to fix mongodb not working (#15) 4 years ago
Abhijeet Singh 1a4be7f98a
Update server.js (#9)
Fixes DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead
See: https://github.com/Automattic/mongoose/issues/5399
4 years ago

@ -1,114 +0,0 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@${PROJECT_NAME}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@${PROJECT_NAME}:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s
/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export NVM_DIR="/home/nvm/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
# set PATH so it includes user's private bin directories
export PATH="$HOME/bin:$HOME/.local/bin:$HOME/node_modules/.bin:$PATH"

3
.gitattributes vendored

@ -0,0 +1,3 @@
# Tell Linguist to exclude HTML files to help Replit language detection.
*.html linguist-vendored
*.css linguist-vendored

@ -1,2 +0,0 @@
[core]
excludesfile = /etc/.gitignore-global

2
.gitignore vendored

@ -0,0 +1,2 @@
.env
node_modules

@ -1,3 +0,0 @@
{"name":"drag-in-files.svg","date":"2016-10-22T16:17:49.954Z","url":"https://cdn.hyperdev.com/drag-in-files.svg","type":"image/svg","size":7646,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/drag-in-files.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(102, 153, 205)","uuid":"adSBq97hhhpFNUna"}
{"name":"click-me.svg","date":"2016-10-23T16:17:49.954Z","url":"https://cdn.hyperdev.com/click-me.svg","type":"image/svg","size":7116,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/click-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(243, 185, 186)","uuid":"adSBq97hhhpFNUnb"}
{"name":"paste-me.svg","date":"2016-10-24T16:17:49.954Z","url":"https://cdn.hyperdev.com/paste-me.svg","type":"image/svg","size":7242,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/paste-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(42, 179, 185)","uuid":"adSBq97hhhpFNUnc"}

@ -0,0 +1 @@
.replit

@ -1,2 +0,0 @@
language = "nodejs"
run = "npm start"

@ -1,13 +1,3 @@
# Exercise Tracker REST API
# Exercise Tracker
#### A microservice project, part of Free Code Camp's curriculum
### User Stories
[![Run on Repl.it](https://repl.it/badge/github/freeCodeCamp/boilerplate-project-exercisetracker)](https://repl.it/github/freeCodeCamp/boilerplate-project-exercisetracker)
1. I can create a user by posting form data username to /api/exercise/new-user and returned will be an object with username and _id.
2. I can get an array of all users by getting api/exercise/users with the same info as when creating a user.
3. I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. Returned will be the user object with also with the exercise fields added.
4. I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). Return will be the user object with added array log and count (total exercise count).
5. I can retrieve part of the log of any user by also passing along optional parameters of from & to or limit. (Date format yyyy-mm-dd, limit = int)
This is the boilerplate for the Exercise Tracker project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/exercise-tracker

@ -0,0 +1,18 @@
const express = require('express')
const app = express()
const cors = require('cors')
require('dotenv').config()
app.use(cors())
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html')
});
const listener = app.listen(process.env.PORT || 3000, () => {
console.log('Your app is listening on port ' + listener.address().port)
})

866
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -2,28 +2,21 @@
"name": "fcc-exercise-tracker",
"version": "0.1.0",
"description": "A REST API project, part of Free Code Camp's curriculum",
"main": "server.js",
"main": "index.js",
"scripts": {
"start": "node server.js"
"start": "node index.js"
},
"dependencies": {
"express": "^4.14.0",
"mongoose": "^4.7.2",
"mongodb": "^2.2.14",
"body-parser": "^1.15.2",
"cors": "^2.8.1",
"shortid": "^2.2.6"
},
"engines": {
"node": "6.9.1"
"dotenv": "^8.2.0",
"express": "^4.16.4",
"cors": "^2.8.5"
},
"repository": {
"url": "https://gomix.com/#!/project/welcome-project"
"url": "https://github.com/freeCodeCamp/boilerplate-project-exercisetracker"
},
"license": "MIT",
"keywords": [
"node",
"gomix",
"express"
]
}

5
public/style.css vendored

@ -1,4 +1,3 @@
* {
box-sizing: border-box;
}
@ -15,10 +14,6 @@ h1 {
}
.bold {
font-weight: bold;
}
p {
max-width: 900px;
}

@ -0,0 +1 @@
PORT=3000

@ -1,48 +0,0 @@
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const cors = require('cors')
const mongoose = require('mongoose')
mongoose.connect(process.env.MLAB_URI || 'mongodb://localhost/exercise-track' )
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html')
});
// Not found middleware
app.use((req, res, next) => {
return next({status: 404, message: 'not found'})
})
// Error Handling middleware
app.use((err, req, res, next) => {
let errCode, errMessage
if (err.errors) {
// mongoose validation error
errCode = 400 // bad request
const keys = Object.keys(err.errors)
// report the first validation error
errMessage = err.errors[keys[0]].message
} else {
// generic or custom error
errCode = err.status || 500
errMessage = err.message || 'Internal Server Error'
}
res.status(errCode).type('txt')
.send(errMessage)
})
const listener = app.listen(process.env.PORT || 3000, () => {
console.log('Your app is listening on port ' + listener.address().port)
})

69
views/index.html vendored

@ -1,35 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Exercise Tracker | freeCodeCamp</title>
<link rel="shortcut icon" href="https://cdn.freecodecamp.org/universal/favicons/favicon.ico" type="image/x-icon" />
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<head>
<title>Exercise Tracker | Free Code Camp</title>
<link rel="shortcut icon" href="https://cdn.hyperdev.com/us-east-1%3A52a203ff-088b-420f-81be-45bf559d01b1%2Ffavicon.ico" type="image/x-icon"/>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<h1>Exercise tracker</h1>
<form action="/api/users" method="post">
<h3>Create a New User</h3>
<p><code>POST /api/users</code></p>
<input id="uname" type="text" name="username" placeholder="username" />
<input type="submit" value="Submit" />
</form>
<form id="exercise-form" method="post">
<h3>Add exercises</h3>
<p><code>POST /api/users/:_id/exercises</code></p>
<input id="uid" type="text" name=":_id" placeholder=":_id" />
<input id="desc" type="text" name="description" placeholder="description*" />
<input id="dur" type="text" name="duration" placeholder="duration* (mins.)" />
<input id="date" type="text" name="date" placeholder="date (yyyy-mm-dd)" />
<input type="submit" value="Submit" />
</form>
<p>
<strong>GET user's exercise log: </strong>
<code>GET /api/users/:_id/logs?[from][&amp;to][&amp;limit]</code>
</p>
<p><strong>[ ]</strong> = optional</p>
<p><strong>from, to</strong> = dates (yyyy-mm-dd); <strong>limit</strong> = number</p>
</div>
<script>
const exerciseForm = document.getElementById("exercise-form");
<body>
<div class="container">
<h1>Exercise tracker</h1>
<form action="/api/exercise/new-user" method="post">
<h3>Create a New User</h3>
<p><code>POST /api/exercise/new-user</code></p>
<input id="uname" type="text" name="username" placeholder="username">
<input type="submit" value="Submit">
</form>
<form action="/api/exercise/add" method="post">
<h3>Add exercises</h3>
<p><code>POST /api/exercise/add</code></p>
<input id="uid" type="text" name="userId" placeholder="userId*">
<input id="desc" type="text" name="description" placeholder="description*">
<input id="dur" type="text" name="duration" placeholder="duration* (mins.)">
<input id="dat" type="text" name="date" placeholder="date (yyyy-mm-dd)">
<input type="submit" value="Submit">
</form>
<p><strong>GET users's exercise log: </strong><code>GET /api/exercise/log?{userId}[&amp;from][&amp;to][&amp;limit]</code></p>
<p><strong>{ }</strong> = required, <strong>[ ]</strong> = optional</p>
<p><strong>from, to</strong> = dates (yyyy-mm-dd); <strong>limit</strong> = number</p>
</div>
</body>
exerciseForm.addEventListener("submit", () => {
const userId = document.getElementById("uid").value;
exerciseForm.action = `/api/users/${userId}/exercises`;
exerciseForm.submit();
});
</script>
</body>
</html>

Loading…
Cancel
Save