This is the api for the Truenorth application.
Install dependencies
npm install
Create a .env.development file with this:
DATABASE_URL="mysql://root:secret@localhost:3307/truenorth"
RANDOM_API_KEY="5878cbc4-8af3-4918-a6d7-3905f55cbd31"
PORT=4000
JWT_ACCESS_SECRET=123321
JWT_REFRESH_SECRET=123921
FRONTEND_WEBSITE="http://localhost:3000"
Create a .env.test file with this:
DATABASE_URL="mysql://root:secret@localhost:3307/test_truenorth"
JWT_ACCESS_SECRET=123321
JWT_REFRESH_SECRET=123921
If mysql is not installed:
docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=truenorth --name prisma_db -p 3307:3306 mysql:8.0
Run migrations
npm run migrate
Run seed
npm run seed
npm run dev
- URL:
/api/v1/login
- Method:
POST
- Description: This endpoint is used to authenticate a user and obtain an access token.
-
Headers:
Content-Type
:application/json
-
Body:
{ "username": "gabrielc", "password": "abc123" }
-
Success Response (200 OK)
-
Cookies:
jwt
:refresh_token
-
Body:
{ "accessToken": "new_access_token", "userInfo": { "username": "username", "user_id": "user_id" } }
-
- URL:
/api/v1/refresh_token
- Method:
POST
- Description: This endpoint is used to refresh an expired access token by providing a valid refresh token through request cookies.
-
Headers:
Content-Type
:application/json
-
Cookies:
refreshToken
:your_refresh_token_here
-
Success Response (200 OK)
-
Cookies:
jwt
:refresh_token
-
Body:
{ "accessToken": "new_access_token" }
-
- URL:
/api/v1/operations
- Method:
POST
- Description: This endpoint is used to make an operation.
-
Headers:
Content-Type
:application/json
Authorization
:Bearer your_token_here
-
Body:
{ "value1": "number", "value2": "number", "operationType": "string" }
-
Success Response (200 OK)
- Body:
{ "result": "number" }
- URL:
/api/v1/users/:user_id/records
- Method:
GET
- Description: This endpoint is used to retrieve all records from a user.
-
Headers:
Authorization
:Bearer your_token_here
-
Success Response (200 OK)
- Body:
[ { "id": "09ef2322-b8a4-49fd-970f-efb9d5f174a7", "userId": "bc682ca5-d1ae-4a61-a789-b3f4ab91b5ba", "operationId": "e563fad2-db73-42a5-9bbe-6ef750e90718", "amount": 12, "userBalance": 700, "operationResponse": "success", "deleted": false, "createdAt": "2023-10-27T03:32:14.548Z", "updatedAt": "2023-10-27T03:32:14.548Z" } ]
- URL:
/api/v1/records/:id
- Method:
DELETE
- Description: This endpoint is used to delete a record.
-
Headers:
Content-Type
:application/json
Authorization
:Bearer your_token_here
-
Success Response (200 OK)
- Body:
{ "message": "Record deleted successfully" }