Skip to content

marinaescriva/Bruixes_Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bruixes i Fades Backend Project


LOGO


This repository contains the backend code for a mobile web application called Bruixes i Fades.

Frontend of this project: Bruixes i Fades Frontend

About the project

Bruixes i Fades is a board game pub where you can enjoy different beers and play board games with friends.

Project development and ideation

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

Database Design

Database

Stack

MySQLTypeScriptGitThunder Client

Installation

Here's how to install the repository

  1. Clone the repository
 git clone https://github.com/marinaescriva/Bruixes_Backend.git
  1. 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
  1. 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"
  }
}
  1. Run migrations
npm run run-migrations
  1. Run seeders
npm run seeder
  1. Start de server
npm run dev

API Endpoints

How it works
1. User Registration
  • URL: /api/auth/register
  • Method: POST
  • Description: Registers a new user.
Request body:
{
  "nombre": "Ana",
  "email": "[email protected]",
  "password": "224466"
}

===========================
2. User Login
  • URL: /api/auth/login
  • Method: POST
  • Description: Logs in an existing user.
Request body:
{
 "email": "[email protected]",
 "password": "224466"
}

===========================
3. Get All Games
  • 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
    }
  ]
}

===========================
4. Delete Game
  • 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"
}

===========================
5. Get All Tables
  • 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
    }
  ]
}

===========================
6. Delete Tables
  • 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"
}

===========================
7. Get All Users
  • 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"
    }
  ]
}

===========================
8. Get My Profile
  • 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"
}
}

===========================
9. Update Profile
  • 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"
}
}

===========================
10. Delete User
  • 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"
}

===========================
11. Get All Reservas
  • 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"
    }
  ]
}

===========================
12. New Reserva
  • 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"
}
}
}

===========================
13. Get My Reservas
  • 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"
}
]
}

===========================
14. Delete Reserva
  • 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"
}

===========================

Future features

  • 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)

Author

  • Marina Escrivà

LinkedIn

Porfolio

[email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published