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
8,519 changes: 8,519 additions & 0 deletions case1/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions case3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
build
.env
19 changes: 19 additions & 0 deletions case3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Case Pokémon Go!

Utilizou-se da biblioteca readXlsxFile para importar os dados do arquivo PokemonGo.XLSX, que estão no excel, e foi criado uma API usando NodeJS para que possamos consumir estes dados de maneira prática, rápida e automatizada.

Esta API seguiu as práticas RESTful contendo listagens, busca, deletar, paginação e filtros.

## Tecnologias usadas:

- Conceitos de API RESTful
- Modelagem de dados
- NodeJS
- banco de dados MySQL
- Git

## Como iniciar o projeto?

Primeiramente, foi criado um repositório na conta do Github, depois disso cria-se uma branch nova com o nome do projeto (ex: case), em seguida instala as bibliotecas a serem usadas , faz uma arquitetura das páginas, cria os endpoints, válida as requisições e solicita um pull request para a branch do nosso repositório.


11 changes: 11 additions & 0 deletions case3/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
roots: ["<rootDir>/tests"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};



59 changes: 59 additions & 0 deletions case3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "case2",
"version": "1.0.0",
"description": "Olá Dev! Tudo bem?",
"main": "index.js",
"scripts": {
"dev": "ts-node-dev ./src/index.ts",
"start": "node ./build/index.js",
"build": "tsc",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RedFoxTech/vaga-backend-teste.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/RedFoxTech/vaga-backend-teste/issues"
},
"homepage": "https://github.com/RedFoxTech/vaga-backend-teste#readme",
"dependencies": {
"-": "^0.0.1",
"@types/bcryptjs": "^2.4.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.14",
"@types/jsonwebtoken": "^8.5.9",
"@types/knex": "^0.16.1",
"@types/mysql": "^2.15.21",
"@types/uuid": "^8.3.4",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"excel": "^1.0.1",
"excel4node": "^1.8.0",
"express": "^4.18.2",
"file": "^0.2.2",
"jsonwebtoken": "^8.5.1",
"knex": "^2.3.0",
"multer": "^1.4.5-lts.1",
"mysql": "^2.18.1",
"node-xlsx": "^0.21.0",
"read": "^1.0.7",
"read-excel-file": "^5.5.3",
"save": "^2.9.0",
"ts-node-dev": "^2.0.0",
"typescript": "^4.8.4",
"uuid": "^9.0.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/jest": "^29.1.2",
"@types/node": "^18.11.0",
"jest": "^29.2.0",
"ts-jest": "^29.0.3"
}
}
60 changes: 60 additions & 0 deletions case3/request.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//inserir arquivo xlsx no banco de dados
POST http://localhost:3003/pokemon/insert
Content-Type: application/json

###
//criar pokemon
POST http://localhost:3003/pokemon/create
Content-Type: application/json

{
"name":"Fearow",
"type":"normal",
"weather":"Partly cloudy",
"STAT_TOTAL":447,
"ATK":182,
"DEF":135,
"STA": 130
}

//pegar pokemon pelo id
###
GET http://localhost:3003/pokemon/get/1

//pegar pokemon pelo nome
###
GET http://localhost:3003/pokemon/get/Bulbasaur

###
//pegar pokemons
GET http://localhost:3003/pokemon/get

//alterar dados do pokemon pelo id
###
PUT http://localhost:3003/pokemon/change/c220b1a1-05ba-45ee-a7ed-570d3d088ef9
Content-Type: application/json

{
"name":"Spearow",
"type":"normal",
"weather":"Partly cloudy",
"STAT_TOTAL":257,
"ATK":114,
"DEF":61,
"STA": 82
}

// deletar pokemon
###
DELETE http://localhost:3003/pokemon/delete/20

//Fearow normal Partly cloudy 447 182 135 130
//Ekans poison Cloudy 282 110 102 70
//Pikachu electric Rainy 283 112 101 70
//Psyduck water Rainy 318 122 96 100
//Tauros normal Partly cloudy 545 198 197 150
//Snorlax normal Partly cloudy 700 190 190 320
//Flaaffy electric Rainy 397 145 112 140
//Ampharos electric Rainy 563 211 172 180
//Bellossom grass Sunny/clear 508 169 189 150
//Marill water Rainy 270 37 93 140
25 changes: 25 additions & 0 deletions case3/src/Authenticator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AuthenticationData } from "./model/types";
import * as jwt from "jsonwebtoken";

class Authenticator {
generateToken = (payload: AuthenticationData) :string => {
const token = jwt.sign(
payload,
process.env.JWT_KEY as string,
{expiresIn: process.env.JWT_EXPIRES_IN}
)

return token
}

getTokenData = (token: string) :AuthenticationData => {
const result = jwt.verify(
token,
process.env.JWT_KEY as string
) as AuthenticationData

return result
}
}

export default new Authenticator()
133 changes: 133 additions & 0 deletions case3/src/business/PokemonBusiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { CustomError, MissingFieldsToComplete } from "../error/CustomError";
import { Pokemon, PokemonDTO } from "../model/types";
import { IdGenerator } from "../services/IdGenerator";

import { PokemonRepository } from "./PokemonRepository";

export class PokemonBusiness {
constructor(private pokemonDatabase: PokemonRepository) {}

async pokemonBusiness(pokemons: Pokemon[]) {
try {

pokemons.forEach(async(pokemon) => {

let { id,name,type,weather,STAT_TOTAL,ATK,DEF,STA } = pokemon;

if (!id || !name || !type || !weather || !STAT_TOTAL || !ATK || !DEF || !STA ) {
throw new MissingFieldsToComplete();
}

await this.pokemonDatabase.InsertPokemon(pokemon);

});


} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


async createPokemonBusiness(input: PokemonDTO) {
try {

const { name,type,weather,STAT_TOTAL,ATK,DEF,STA } = input;


if ( !name || !type || !weather || !STAT_TOTAL || !ATK || !DEF || !STA ) {
throw new MissingFieldsToComplete();
}

const id = new IdGenerator().generateId();


const pokemon: Pokemon = {
id,
name,
type,
weather,
STAT_TOTAL,
ATK,
DEF,
STA
}

await this.pokemonDatabase.createPokemon(pokemon);


} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


async getPokemonBusiness() {
try {

const pokemons = await this.pokemonDatabase.selectPokemon()

return pokemons;

} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}

async getPokemonByIdBusiness(id: string) {
try {


const pokemons = await this.pokemonDatabase.selectPokemonById(id);

return pokemons;

} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


async getPokemonByNameBusiness(name: string) {

try {

const pokemons = await this.pokemonDatabase.selectByPkemonName(name);

return pokemons;

} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


async deletePokemonByIdBusiness(id: string) {

try {

await this.pokemonDatabase.deletPokemonById(id);



} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


async changePokemonBusiness(id: string,name:string,type:string,weather:string,STAT_TOTAL:number,ATK:number,DEF:number,STA:number) {

try {

await this.pokemonDatabase.changePokemon(id,name,type,weather,STAT_TOTAL,ATK,DEF,STA);



} catch (error: any) {
throw new CustomError(error.statusCode, error.sqlMessage || error.message);
}
}


}
12 changes: 12 additions & 0 deletions case3/src/business/PokemonRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Pokemon } from "../model/types"


export interface PokemonRepository {
InsertPokemon(pokemon: Pokemon): Promise<void>
createPokemon(pokemon: Pokemon): Promise<void>
selectPokemon(): Promise<Pokemon[]>
selectByPkemonName(name: string): Promise<Pokemon>
selectPokemonById(id: string): Promise<Pokemon>
deletPokemonById(id: string): Promise<void>
changePokemon(id:string,name:string,type:string,weather:string,STAT_TOTAL:number,ATK:number,DEF:number,STA:number): Promise< void>;
}
19 changes: 19 additions & 0 deletions case3/src/controller/APP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from "express"
import cors from "cors"
import { AddressInfo } from "net"

export const app = express()

app.use(express.json())
app.use(cors())

const server = app.listen(process.env.PORT || 3003, () => {
if (server) {
const address = server.address() as AddressInfo;
console.log(`Server is running in http://localhost:${address.port}`);
//console.log(`Server is running in ${address.address}:${address.port}`);

} else {
console.error(`Failure upon starting server.`);
}
})
Loading