Back-end for Quer Apostar a sports betting system
This API is available on REnder
https://quer-apostar.onrender.com
- Clone this repository
- Install all dependencies
npm i
- Create a PostgreSQL database with whatever name you want
- Configure the
.env.development
file using the.env.example
file (see "Running application locally or inside docker section" for details) - Run all migrations
npm run dev:migration:run
- Run the back-end in a development environment:
npm run dev
- Follow the steps in the last section
- Configure the
.env.test
file using the.env.example
file (see "Running application locally or inside docker" section for details) - Run all migrations:
npm run test:migration:run
- Run test:
npm run test
npm run build
npm start
Create a network
docker network create --driver bridge qa-network
Create a volume
docker volume create qa-volume
Run a postgres container inside the created network and using the created volume
docker run --name pg-querapostar --network=qa-network -e POSTGRES_PASSWORD=postgres -p 5433:5432 -v qa-volume:/var/lib/postgresql/data -d postgres
docker run -d --name querapostar --network=qa-network -e POSTGRES_HOST=pg-querapostar -p 4040:4000 diegobeker/quer-apostar-quanto
Check it out on localhost/4040/health
Clone this repository and run
docker build -t myusername/myimage:tag .
docker run -d --name my-container -p 4040:4000 myusername/myimage:tag
Check it out on localhost/4040/health
Clone this repository and run
docker compose up
docker compose down
{
id: number; // ex: 1
createdAt: string; // ex: "2023-09-27T19:22:50.503Z"
updatedAt: string; // ex: "2023-09-27T19:22:50.503Z"
name: string; // ex: "James"
balance: number; // balance of a participant in cents, ex: 1000 ($ 10,00)
}
{
id: number; // game id
createdAt: string;
updatedAt: string;
homeTeamName: string; // ex: "Flamengo"
awayTeamName: string; // ex: "Fluminense"
homeTeamScore: number; // score of Home team, ex: 3
awayTeamScore: number; // score of away team, ex: 1
isFinished: boolean; // true if game is finished, false if it is not finished
}
{
id: number; // bet id
createdAt: string;
updatedAt: string;
homeTeamScore: number; // bet on score of Home team, ex: 3,
awayTeamScore: number; // bet on score of Away team, ex: 2,
amountBet: number; // amount bet in cents
gameId: number; // game id
participantId: number; // participant id that made the bet
status: string; // state of the bet, it can be PENDING (game is not finished), WON (got the final score right) ou LOST (got the final score wrong)
amountWon: number || null; // amount won or null while the bet status is PENDING
}
-
Create a participant with an initial balance
-
Request Body: name and balance
{
"name": "Diego",
"balance": 10000, // represented in cents, must be 10000 or greater
}
- Response: participant created
{
"id": 65,
"createdAt": "2023-10-08T14:38:56.720Z",
"updatedAt": "2023-10-08T14:50:52.898Z",
"name": "Yasmin Pereira",
"balance": 659801
}
-
Create a new game with initial score 0x0 and isFinished = false
-
Request Body: home team and away team names
{
"homeTeamName": "Flamengo",
"awayTeamName": "Fluminense"
}
- Response: game created
{
"id": 76,
"createdAt": "2023-10-08T22:28:03.779Z",
"updatedAt": "2023-10-08T22:28:03.779Z",
"homeTeamName": "Flamengo",
"awayTeamName": "Fluminense",
"homeTeamScore": 0,
"awayTeamScore": 0,
"isFinished": false
}
-
Create a bet that belong to a participant in a specific game
-
Request Body: home team and away team names
{
"homeTeamScore": 3,
"awayTeamScore": 2,
"amountBet": 1000,
"gameId": 75,
"participantId": 67
}
- Response: bet created
{
"id": 32,
"createdAt": "2023-10-08T22:57:34.602Z",
"updatedAt": "2023-10-08T22:57:34.602Z",
"homeTeamScore": 3,
"awayTeamScore": 2,
"amountBet": 1000,
"gameId": 76,
"participantId": 67,
"status": "PENDING",
"amountWon": null
}
-
Finish a game and update all bets that belong to that game, also update the balance of participants.
-
Request Body: home team and away team names
{
"homeTeamScore": 3,
"awayTeamScore": 2
}
- Response: game finished
{
"id": 76,
"createdAt": "2023-10-08T22:28:03.779Z",
"updatedAt": "2023-10-08T23:00:11.027Z",
"homeTeamName": "Flamengo",
"awayTeamName": "Fluminense",
"homeTeamScore": 3,
"awayTeamScore": 2,
"isFinished": true
}
-
Return all participants with current balance
-
Response: all participants
[
{
"id": 66,
"createdAt": "2023-10-08T14:38:57.030Z",
"updatedAt": "2023-10-08T14:38:57.030Z",
"name": "Lorena Xavier",
"balance": 229050
},
{
"id": 67,
"createdAt": "2023-10-08T14:49:40.128Z",
"updatedAt": "2023-10-08T22:57:34.555Z",
"name": "Jose",
"balance": 11500
}
]
- Return all games
[
{
"id": 75,
"createdAt": "2023-10-08T14:49:56.005Z",
"updatedAt": "2023-10-08T14:51:49.718Z",
"homeTeamName": "Flamengo",
"awayTeamName": "Fluminense",
"homeTeamScore": 3,
"awayTeamScore": 2,
"isFinished": true
},
{
"id": 76,
"createdAt": "2023-10-08T22:28:03.779Z",
"updatedAt": "2023-10-08T23:00:11.027Z",
"homeTeamName": "Corinthians",
"awayTeamName": "Palmeiras",
"homeTeamScore": 0,
"awayTeamScore": 0,
"isFinished": false
}
]
- Return a specifc game with all bets of that game
{
"id": 76,
"createdAt": "2023-10-08T22:28:03.779Z",
"updatedAt": "2023-10-08T23:00:11.027Z",
"homeTeamName": "Flamengo",
"awayTeamName": "Fluminense",
"homeTeamScore": 3,
"awayTeamScore": 2,
"isFinished": true,
"Bet": [
{
"id": 32,
"createdAt": "2023-10-08T22:57:34.602Z",
"updatedAt": "2023-10-08T22:57:34.602Z",
"homeTeamScore": 3,
"awayTeamScore": 2,
"amountBet": 1000,
"gameId": 76,
"participantId": 67,
"status": "WON",
"amountWon": 700
}
]
}