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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
.build
node_modules
1,625 changes: 1,625 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "teste_backend_pokemon",
"version": "1.0.0",
"description": "Olá Dev! Tudo bem?",
"main": "index.js",
"scripts": {
"dev": "ts-node-dev ./src/index.ts",
"start": "tsc && node ./build/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/knex": "^0.16.1",
"@types/node": "^18.15.7",
"@types/typescript": "^2.0.0",
"cors": "^2.8.5",
"custom": "^0.0.0",
"custom-error": "^0.2.1",
"dotenv": "^16.0.3",
"error": "^10.4.0",
"express": "^4.18.2",
"knex": "^2.4.2",
"mysql": "^2.18.1",
"node": "^19.8.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.0.2"
}
}
32 changes: 32 additions & 0 deletions pokemonTable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Active: 1679663953655@@35.226.146.116@3306@jbl-4416472-mauricio-toledo
CREATE TABLE IF NOT EXISTS Pokemon(

Name VARCHAR(255) NOT NULL,
Pokedex_number INT,
Img_name VARCHAR(255) DEFAULT NULL,
Generation INT,
Evolution_stage VARCHAR(255) DEFAULT NULL,
Evolved INT,
Family_id VARCHAR(255) DEFAULT NULL,
Cross_gen INT,
Type_1 VARCHAR(255),
Type_2 VARCHAR(255) DEFAULT NULL ,
Weather_1 VARCHAR(255),
Weather_2 VARCHAR(255) DEFAULT NULL ,
STAT_TOTAL BIGINT ,
ATK BIGINT,
DEF BIGINT,
STA BIGINT,
Legendary INT,
Aquireable INT ,
Spawns INT ,
Regional INT,
Raidable INT,
Hatchable INT,
Shiny INT,
Nest INT,
New INT,
Not_gettable INT,
Future_evolve INT,
100_cp_40 INT,
100_cp_39 INT)
1 change: 1 addition & 0 deletions request.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET http://localhost:3003/pokemon
13 changes: 13 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import express from "express"
import cors from "cors"
import dotenv from "dotenv"

dotenv.config()

export const app = express()
app.use(express.json())
app.use(cors())

app.listen(process.env.PORT || 3003, () => {
console.log(`Server is running on port ${process.env.PORT || 3003}`)
})
22 changes: 22 additions & 0 deletions src/business/PokemonBusiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PokemonDataBase } from "../data/PokemonDataBase";
import { CustomError } from "../error/CustomError";

const pokemonDatabase = new PokemonDataBase();

export class PokemonBusiness {

gottaCatchAll = async()=>{

try {

const result = await pokemonDatabase.gottaCatchAll()

return result;

} catch (error:any) {

throw new CustomError(error.statusCode,error.message);

}
}
}
18 changes: 18 additions & 0 deletions src/controller/PokemonController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Request,Response } from "express";
import { PokemonBusiness } from "../business/PokemonBusiness";

const pokemonBusiness = new PokemonBusiness();

export class PokemonController {
gottaCatchAll = async (req: Request, res: Response) => {
try {
const result = await pokemonBusiness.gottaCatchAll()

res.status(200).send(result);

} catch (error:any) {

res.status(400).send({error:error.message});}

}
}
19 changes: 19 additions & 0 deletions src/data/BaseDataBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import dotenv from "dotenv";
import knex from "knex";

dotenv.config();

export default class BaseDataBase {

protected static connection = knex({
client: "mysql",
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_SCHEMA,
port: 3306,
multipleStatements: true
},
})
}
25 changes: 25 additions & 0 deletions src/data/PokemonDataBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import BaseDataBase from "./BaseDataBase";
import { CustomError } from "../error/CustomError";

export class PokemonDataBase extends BaseDataBase {

public TABLE_NAME = "Pokemon"

// retorna todos Pokemons

gottaCatchAll = async () => {

try {

const result = await PokemonDataBase.connection().select("*").from(this.TABLE_NAME);

return result;


} catch (error:any) {

throw new CustomError(error.sqlError,error.message)

}
}
}
5 changes: 5 additions & 0 deletions src/error/CustomError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class CustomError extends Error {
constructor(statusCode: number, message: string){
super(message)
}
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { app } from "./app";
import { PokemonRouter } from "./router/PokemonRouter";

app.use("",PokemonRouter);
11 changes: 11 additions & 0 deletions src/router/PokemonRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from "express"
import { PokemonDataBase } from "../data/PokemonDataBase"
import { PokemonBusiness } from "../business/PokemonBusiness"
import { PokemonController } from "../controller/PokemonController"

export const PokemonRouter = express.Router()

const pokemonController = new PokemonController()


PokemonRouter.get("/pokemon", pokemonController.gottaCatchAll)
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}