Server application for the Jifunze app (spaced repetition capstone) by James Moua and Malcolm Kiano
This project is the server application for the Jifunze app. It consists of a database, a test database, 3 tables, 3 routers, and 6 endpoints
Project is created with:
- Express
- PSQL
- Knex
- Authentication e.g. BcryptJS
- Middleware e.g. Morgan
- JavaScript
- NodeJS
Project is tested with:
- Postgrator-cli@3.2.0
- Mocha
- Chai
- Supertest
- Nodemon
If using user dunder-mifflin
:
mv example.env .env
createdb -U dunder-mifflin spaced-repetition
createdb -U dunder-mifflin spaced-repetition-test
If your dunder-mifflin
user has a password be sure to set it in .env
for all appropriate fields. Or if using a different user, update appropriately.
npm install
npm run migrate
env TEST_DATABASE_=spaced-repetition-test npm run migrate
And npm test
should work at this point
For tests involving time to run properly, configure your Postgres database to run in the UTC timezone.
-
Locate the
postgresql.conf
file for your Postgres installation.- E.g. for an OS X, Homebrew install:
/usr/local/var/postgres/postgresql.conf
- E.g. on Windows, maybe:
C:\Program Files\PostgreSQL\11.2\data\postgresql.conf
- E.g on Ubuntu 18.04 probably:
'/etc/postgresql/10/main/postgresql.conf'
- E.g. for an OS X, Homebrew install:
-
Find the timezone line and set it to UTC:
# - Locale and Formatting -
datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
timezone = 'UTC'
#timezone_abbreviations = 'Default' # Select the set of available time zone
Start the application npm start
Start nodemon for the application npm run dev
Run the tests mode npm test
Run the migrations up npm run migrate
Run the migrations down npm run migrate -- 0
handles the authentication, making sure both username and password match for existing registered accounts
JSON Object requires:
- username: string
- password: string
{
"authToken": eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJuYW1lIjoiSmlmdW56ZSBBZG1pbiIsImlhdCI6MTU5MDA3NjQ0MiwiZXhwIjoxNTkwMDg3MjQyLCJzdWIiOiJhZG1pbiJ9.rwoEogsEQYkPDwOrMQTmLG9QDlZleQt7wKNB563A8K8"
}
handles the refresh of the user's auth token
JSON Object requires:
- valid JSON Web Token
{
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJuYW1lIjoiSmlmdW56ZSBBZG1pbiIsImlhdCI6MTU5MDA3NzE5NywiZXhwIjoxNTkwMDg3OTk3LCJzdWIiOiJhZG1pbiJ9.KISz0KYn6DdgPL-S5zVIG_4YD90c6dFl8yGSR81tljI"
}
gets all of the languages and words
{
"language": {
"id": 1,
"name": "Swahili",
"user_id": 1,
"head": 1,
"total_score": 0
},
"words": [
{
"id": 1,
"language_id": 1,
"original": "mazoezi",
"translation": "practice",
"next": 2,
"memory_value": 1,
"correct_count": 0,
"incorrect_count": 0
},
]
}
gets the current word
{
"nextWord": "mazoezi",
"totalScore": 0,
"wordCorrectCount": 0,
"wordIncorrectCount": 0
}
handles whether the user guessed the current word correctly, then updates the score in the database
JSON Object requires:
- guess: string
{
"answer": "practice",
"isCorrect": false,
"nextWord": "jambo",
"totalScore": 0,
"wordCorrectCount": 0,
"wordIncorrectCount": 0
}
handles the registration, making sure that the user's username is not already taken when registering
JSON Object requires:
- name: string
- username: string
must not already exist in database
- password: string
7 letters minimum, one uppercase, one number, and one special character
{
"id": 2,
"name": "geon",
"username": "admin1"
}