Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="mysql://root:root@mysql:3306/base_datos_prueba"
PORT=3000
MYSQL_ROOT_PASSWORD=root
SECRET=371309bcb7cb788c18fcba4eba01bd63
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
# Keep environment variables out of version control
.env
dist
.pnpm-store
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:20
RUN apt-get install openssl -y
RUN npm install -g pnpm
RUN mkdir -p /home/app
COPY . /home/app/
WORKDIR /home/app
RUN pnpm install
EXPOSE 3000
CMD ["pnpm", "run", "dev"]
29 changes: 29 additions & 0 deletions RUN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Run project
```
docker compose up -d # run project
docker exec -it app sh -c "pnpm prisma db push" #run on completion of mysql container configuration
```
# Docker Container
* app
* mysql
* adminer

## App

The application is running on port 3000, rename .env.example to .env to make it work correctly.

### Endpoints

| URL | Protected | Body Or Param|
| --- | ----------- | --- |
| http://localhost:3000/api/auth/login | **false** | `{ "Email": "example@email.com", "Password": "123456" }`|
| http://localhost:3000/api/users/register | **false** | `{"Name":"John Doe","Email":"example@email.com" , "Password":"123456"} `|
| http://localhost:3000/api/pokemons | **true** | |
| http://localhost:3000/api/pokemons/add/:param | **true** | `25` or `pikachu` |
| http://localhost:3000/api/pokemons/favorites/add/:param | **true** | `25` or `pikachu` |

## Mysql
when the mysql image is generated it creates the database named base_datos_prueba and the password is in the .env file in the variable MYSQL_ROOT_PASSWORD
## Adminer

The adminer is database management, run in port 8080
64 changes: 64 additions & 0 deletions db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CREATE DATABASE `base_datos_prueba` ;
USE `base_datos_prueba`;

CREATE TABLE `Favorites` (
`UserId` int NOT NULL,
`PokemonId` int NOT NULL,
`CreationDate` datetime(3) NOT NULL,
PRIMARY KEY (`PokemonId`,`UserId`),
KEY `Favorites_UserId_fkey` (`UserId`)
);


CREATE TABLE `Pokemons` (
`Id` int NOT NULL AUTO_INCREMENT,
`PokemonId` int NOT NULL,
`UserId` int NOT NULL,
`Name` varchar(50) NOT NULL,
`Games` varchar(191) NOT NULL,
`Abilities` varchar(191) NOT NULL,
`UpdatedDate` datetime(3) NOT NULL,
`CreationDate` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`Id`),
UNIQUE KEY `Pokemons_Id_key` (`Id`),
UNIQUE KEY `Pokemons_PokemonId_UserId_key` (`PokemonId`,`UserId`),
KEY `Pokemons_UserId_fkey` (`UserId`)
);


CREATE TABLE `PokemonsType` (
`PokemonId` int NOT NULL,
`TypeId` int NOT NULL,
`CreationDate` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`PokemonId`,`TypeId`),
UNIQUE KEY `PokemonsType_PokemonId_TypeId_key` (`PokemonId`,`TypeId`),
KEY `PokemonsType_TypeId_fkey` (`TypeId`)
);


CREATE TABLE `Types` (
`Id` int NOT NULL AUTO_INCREMENT,
`Name` varchar(50) NOT NULL,
`CreationDate` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`Id`),
UNIQUE KEY `Types_Id_key` (`Id`),
UNIQUE KEY `Types_Name_key` (`Name`)
);


CREATE TABLE `Users` (
`Id` int NOT NULL AUTO_INCREMENT,
`Name` varchar(50) NOT NULL,
`Email` varchar(50) NOT NULL,
`Password` varchar(250) NOT NULL,
`CreationDate` datetime(3) DEFAULT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `Users_Id_key` (`Id`),
UNIQUE KEY `Users_Email_key` (`Email`)
);

ALTER TABLE `Favorites` ADD CONSTRAINT `Favorites_PokemonId_fkey` FOREIGN KEY (`PokemonId`) REFERENCES `Pokemons` (`Id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `Favorites` ADD CONSTRAINT `Favorites_UserId_fkey` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `Pokemons` ADD CONSTRAINT `Pokemons_UserId_fkey` FOREIGN KEY (`UserId`) REFERENCES `Users` (`Id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `PokemonsType` ADD CONSTRAINT `PokemonsType_PokemonId_fkey` FOREIGN KEY (`PokemonId`) REFERENCES `Pokemons` (`Id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `PokemonsType` ADD CONSTRAINT `PokemonsType_TypeId_fkey` FOREIGN KEY (`TypeId`) REFERENCES `Types` (`Id`) ON DELETE RESTRICT ON UPDATE CASCADE;
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'
services:
mysql:
container_name: mysql
env_file:
- .env
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: base_datos_prueba
ports:
- 3306:3306
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- 8080:8080
app:
image: app:dev
container_name: app
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "prueba",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "tsc && node --env-file=.env dist/app.js",
"dev": "ts-node-dev --env-file=.env src/app.ts "
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.11.27",
"prisma": "^5.11.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.2"
},
"dependencies": {
"@prisma/client": "5.11.0",
"bcryptjs": "^2.4.3",
"express": "^4.18.3",
"jsonwebtoken": "^9.0.2"
}
}
Loading