- Copy
.env.example
and name it.env
- Create a postgres database and add its URL into the
DATABASE_URL
environment variable, keeping?schema=prisma
on the end- Postgres db URLs are in the format:
postgres://[USERNAME]:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NAME]
- Note that prisma doesn't store data in the public schema, so set the search path to prisma in your db client. For PSQL client
- use
\dn
to show available schemas - use SQL to set the search path to the correct schema:
SET search_path to prisma;
\dt
will then show available tables (once migrations have been run)
- Postgres db URLs are in the format:
- If using a cloud database provider:
- Create another database and run
create schema shadow
on it - Add its URL into the
SHADOW_DATABASE_URL
env var, keeping?schema=shadow
on the end
- Create another database and run
npm ci
to install dependenciesnpx prisma migrate reset
to apply migrations to your dbnpm run dev
to run the app
If you use Insomnia, you can import this request collection .json file in the ./assets/
folder to hit the ground running with all of the requests ready to test.
POST /user
Example Request
curl -X POST http://localhost:4000/user \
-H 'Content-Type: application/json' \
-d '{"first_name":"Nathan","last_name":"King","email":"ngk5@gmail.com","password":"mysecurepassword","biography":"Hello world","github_url":"https://github.com/vherus"}'
Example body
{
"first_name": "Nathan",
"last_name": "King",
"email": "ngk5@gmail.com",
"password": "mysecurepassword",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
}
Example response
{
"status": "success",
"data": {
"user": {
"id": 8,
"cohort_id": null,
"role": "STUDENT",
"first_name": "Nathan",
"last_name": "King",
"email": "ngk5@gmail.com",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
}
}
}
POST /login
Example body{
"email": "ngk5@gmail.com",
"password": "mysecurepassword"
}
Example response
{
"status": "success",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjUsImlhdCI6MTY0OTQxMzk0OSwiZXhwIjoxNjQ5NTAwMzQ5fQ.b37lSRtpFWJ9kqUYAc6PUIP28JXjAYtBN_GpU5TcEuc",
"user": {
"id": 5,
"cohort_id": null,
"role": "STUDENT",
"first_name": "Nathan",
"last_name": "King",
"email": "ngk2@gmail.com",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
}
}
}
POST /post (hardcoded responses)
HeadersAuthorization: Bearer <token>
Example body
{
"content": "Hello world!"
}
Example response
{
"status": "success",
"data": {
"post": {
"id": 1,
"content": "Hello world!"
}
}
}
POST /cohort
Only auth tokens for users with the TEACHER role can use this routeHeaders
Authorization: Bearer <token>
Example body
{
"cohort_name": "Desperados"
}
Example response
{
"status": "success",
"data": {
"cohort": {
"id": 3,
"cohort_name": "Desperados"
}
}
}
POST /log (hardcoded responses)
Only auth tokens for users with the TEACHER role can use this routeHeaders
Authorization: Bearer <token>
Example body
{
"date": "2022-05-05",
"cohort_id": 3,
"lines": [
{
"content": "Caught up with James"
},
{
"content": "Punished Joel"
}
]
}
Example response
{
"status": "success",
"data": {
"log": {
"id": 1,
"cohort_id": 3,
"date": "2022-05-05",
"author": {
"id": 5,
"first_name": "Nathan",
"last_name": "King"
},
"lines": [
{
"id": 1,
"content": "Caught up with James"
},
{
"id": 2,
"content": "Punished Joel"
}
]
}
}
}
GET /posts (hardcoded responses)
HeadersAuthorization: Bearer <token>
Example response
{
"status": "success",
"data": {
"posts": [
{
"id": 1,
"content": "Hello world!",
"author": {
"id": 5,
"cohortId": null,
"firstName": "Nathan",
"lastName": "King",
"email": "ngk2@gmail.com",
"bio": "Hello world",
"githubUrl": "https://github.com/vherus",
"role": "STUDENT"
}
},
{
"id": 2,
"content": "Hello from the void!",
"author": {
"id": 5,
"cohortId": null,
"firstName": "Nathan",
"lastName": "King",
"email": "ngk2@gmail.com",
"bio": "Hello world",
"githubUrl": "https://github.com/vherus",
"role": "STUDENT"
}
}
]
}
}
GET /user/:id
HeadersAuthorization: Bearer <token>
Example response
{
"status": "success",
"data": {
"user": {
"id": 1,
"cohort_id": null,
"role": "STUDENT",
"first_name": "Nathan",
"last_name": "King",
"email": "ngk6@gmail.com",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
}
}
}
GET /users?first_name=Name
The first_name query parameter is optional and case sensitiveThe cohort_id query parameter is optional
Headers
Authorization: Bearer <token>
Example response
{
"status": "success",
"data": {
"users": [
{
"id": 1,
"cohort_id": null,
"role": "STUDENT",
"first_name": "Nathan",
"last_name": "King",
"email": "nk3@gmail.com",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
},
{
"id": 3,
"cohort_id": null,
"role": "STUDENT",
"first_name": "Nathan",
"last_name": "Queen",
"email": "nk2@gmail.com",
"biography": "Hello world",
"github_url": "https://github.com/vherus"
}
]
}
}
GET /courses
Headers
Authorization: Bearer <token>
Example response
{
"status": "success",
"data": [
{
"id": 4,
"courseName": "Web Development",
"createdAt": "2022-07-08T14:59:35.467Z",
"updatedAt": "2022-07-08T11:31:07.143Z",
"modules": [
{
"id": 1,
"moduleName": "Javascript Basics",
"courseId": 4,
"createdAt": "2022-07-08T15:06:38.837Z",
"updatedAt": "2022-07-08T11:31:07.143Z",
"units": [
{
"id": 1,
"unitName": "Arrays Fundamentals",
"moduleId": 1,
"createdAt": "2022-07-08T15:07:59.535Z",
"updatedAt": "2022-07-08T11:31:07.143Z",
"exercises": [
{
"id": 4,
"exerciseName": "Fruity Loops",
"githubUrl": "https://github.com/hopping",
"unitId": 1,
"createdAt": "2022-07-08T15:10:26.783Z",
"updatedAt": "2022-07-08T11:31:07.143Z"
}
]
}
]
}
]
}
]
}
PATCH /user/:id (hardcoded responses)
Only auth tokens for users with the TEACHER role can use this routeHeaders
Authorization: Bearer <token>
Example body
{
"cohort_id": 3
}
Example response
{
"status": "success",
"data": {
"user": {
"cohort_id": 3
}
}
}