This repository contains the backend code for a mobile web application called Bruixes i Fades.
Frontend of this project: Bruixes i Fades Frontend
Bruixes i Fades is a board game pub where you can enjoy different beers and play board games with friends.
The project idea stems from a local café near my home, for which I created a comprehensive graphic identity project in 2022: Bruixes i Fades
Here's how to install the repository
- Clone the repository
git clone https://github.com/marinaescriva/Bruixes_Backend.git
- Connect the repository to the database using the .env.sample file as a template
PORT=4001
DB_USER=user
DB_ROOT_PASSWORD=12345
DB_PORT=3312
DB_HOST=localhost
DB_DATABASE=bruixes_i_fades_example
JWT_SECRET=jwtsecret
- Add the scripts and dependences to the package.json
{
"name": "bruixes_back_ts",
"version": "1.0.0",
"description": "API for Bruixes i Fades",
"main": "server.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon ./src/server.ts",
"run-migrations": "npx typeorm-ts-node-commonjs migration:run -d ./src/database/db.ts",
"revert-migrations": "npx typeorm-ts-node-commonjs migration:revert -d ./src/database/db.ts",
"build": "tsc",
"start": "node ./dist/server.js",
"seeder": "ts-node ./src/Database/seeders/seeder.ts"
},
"dependencies": {
"@faker-js/faker": "^8.4.1",
"@types/cors": "^2.8.17",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"faker": "^6.6.6",
"jsonwebtoken": "^9.0.2",
"mysql2": "^3.9.7",
"reflect-metadata": "^0.2.2",
"typeorm": "^0.3.20"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.12.7",
"nodemon": "^3.1.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.5"
}
}
- Run migrations
npm run run-migrations
- Run seeders
npm run seeder
- Start de server
npm run dev
How it works
- URL: /api/auth/register
- Method: POST
- Description: Registers a new user.
Request body:
{
"nombre": "Ana",
"email": "[email protected]",
"password": "224466"
}
===========================
- URL: /api/auth/login
- Method: POST
- Description: Logs in an existing user.
Request body:
{
"email": "[email protected]",
"password": "224466"
}
===========================
- URL: /api/games
- Method: GET
- Description: Retrieves all games available.
- Request: token on Auth/Bearer.
Response:
{
"success": true,
"data": [
{
"id": 1,
"nombre": "Catan",
"jugadores": 4,
"isAvailable": true
},
{
"id": 2,
"nombre": "Ticket to Ride",
"jugadores": 5,
"isAvailable": true
},
{
"id": 3,
"nombre": "Pandemic",
"jugadores": 4,
"isAvailable": false
}
]
}
===========================
- URL: /api/games/:id
- Method: DELETE
- Description: Deletes a game by its ID.
- Request: token of Super Admin on Auth/Bearer.
Response:
{
"success": true,
"message": "Game deleted"
}
===========================
- URL: /api/tables
- Method: GET
- Description: Retrieves all available tables.
- Request: token on Auth/Bearer.
Response:
{
"success": true,
"data": [
{
"id": 1,
"numero": 1,
"capacidad": 4,
"isAvailable": true
},
{
"id": 2,
"numero": 2,
"capacidad": 6,
"isAvailable": true
},
{
"id": 3,
"numero": 3,
"capacidad": 8,
"isAvailable": false
}
]
}
===========================
- URL: /api/tables/:id
- Method: DELETE
- Description: Deletes a table by its ID.
- Request: token of Super Admin on Auth/Bearer.
Response:
{
"success": true,
"message": "Table deleted"
}
===========================
- URL: /api/users
- Method: GET
- Description: Retrieves all users.
- Request: token of Super Admin on Auth/Bearer.
Response:
{
"success": true,
"data": [
{
"id": 1,
"nombre": "John Doe",
"email": "[email protected]",
"createdAt": "2024-04-24T12:00:00Z",
"updatedAt": "2024-04-24T12:00:00Z"
},
{
"id": 2,
"nombre": "Jane Smith",
"email": "[email protected]",
"createdAt": "2024-04-24T12:00:00Z",
"updatedAt": "2024-04-24T12:00:00Z"
}
]
}
===========================
- URL: /api/users/profile
- Method: GET
- Description: Retrieves the profile of the current user.
- Request: token on Auth/Bearer.
Response:
{
"success": true,
"data": {
"id": 1,
"nombre": "John Doe",
"email": "[email protected]",
"createdAt": "2024-04-24T12:00:00Z",
"updatedAt": "2024-04-24T12:00:00Z"
}
}
===========================
- URL: /api/users/profile
- Method: PUT
- Description: Updates the profile of the current user. (Can update name and/or email)
- Request: token on Auth/Bearer.
Request body:
{
"nombre": "John Smith",
"email": "[email protected]"
}
Response:
{
"success": true,
"message": "User updated",
"data": {
"id": 1,
"nombre": "John Smith",
"email": "[email protected]",
"createdAt": "2024-04-24T12:00:00Z",
"updatedAt": "2024-04-24T12:00:00Z"
}
}
===========================
- URL: /api/users/:id
- Method: DELETE
- Description: Deletes a user by its ID.
- Request: token of Super Admin on Auth/Bearer.
Response:
{
"success": true,
"message": "User deleted successfuly"
}
===========================
- URL: /api/reservas
- Method: GET
- Description: Retrieves all reservations.
- Request: token of Super Admin on Auth/Bearer.
Response:
{
"success": true,
"data": [
{
"id": 1,
"idUsuario": 1,
"idMesa": 1,
"idJuego": 1,
"idEvento": null,
"fechaHoraInicio": "2024-04-25T12:00:00Z"
},
{
"id": 2,
"idUsuario": 2,
"idMesa": 2,
"idJuego": null,
"idEvento": null,
"fechaHoraInicio": "2024-04-25T13:00:00Z"
}
]
}
===========================
- URL: /api/reservas
- Method: POST
- Description: Creates a new reservation.
- Request: token on Auth/Bearer.
Request body:
{
"idMesa": 1,
"idJuego": 1,
"fechaHoraInicio": "2024-04-26T14:00:00Z"
}
Response:
{
"success": true,
"message": "Reserva creada exitosamente",
"data": {
"reservaId": {
"id": 3,
"idUsuario": 1,
"idMesa": 1,
"idJuego": 1,
"idEvento": null,
"fechaHoraInicio": "2024-04-26T14:00:00Z"
}
}
}
===========================
- URL: /api/misreservas
- Method: GET
- Description: Retrieves reservations of the current user.
- Request: token on Auth/Bearer.
Response:
{
"success": true,
"data": [
{
"id": 1,
"idUsuario": 1,
"idMesa": 1,
"idJuego": 1,
"idEvento": null,
"fechaHoraInicio": "2024-04-25T12:00:00Z"
}
]
}
===========================
- URL: /api/reservas/:id
- Method: DELETE
- Description: Deletes a reservation by its ID.
- Request: token of Super Admin or owner on Auth/Bearer.
Response:
{
"success": true,
"message": "Reserva deleted"
}
===========================
- Add events to join
- Limit reservations choose diferent params like date/table/game to allow more options
- Add more information about games ( players , duration..etc)
- Marina Escrivà