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
Binary file removed Pokemon Go.xlsx
Binary file not shown.
36 changes: 0 additions & 36 deletions README.md

This file was deleted.

5 changes: 5 additions & 0 deletions pokemongo/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}
18 changes: 18 additions & 0 deletions pokemongo/.docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:10.16.3

# Atualizando / Instalando pacotes
RUN apt-get update && apt-get install apt-utils nano vim libcups2-dev -y

RUN mkdir -p /app/home
WORKDIR /app/home

# Copiando aplicacao pro lado do volume
COPY . .

# Clonando env
COPY .env.example .env

# Instalando dependencias
RUN npm install

EXPOSE 3333
13 changes: 13 additions & 0 deletions pokemongo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions pokemongo/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NODE_ENV=development
APP_NAME=pokemongo
APP_PORT=3333
MONGO_HOST=mongo
MONGO_PORT=27017
MONGO_USER=
MONGO_PASSWORD=
MONGO_COLLECTION=pokemongo
24 changes: 24 additions & 0 deletions pokemongo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true
},
extends: 'standard',
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
use: 'readonly'
},
parserOptions: {
ecmaVersion: 2018
},
rules: {
camelcase: [
'error', {
properties: 'never',
ignoreDestructuring: true
}
]
}
}
11 changes: 11 additions & 0 deletions pokemongo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Node modules
/node_modules
package-lock.json
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
/.idea
.env

/uploads/*
13 changes: 13 additions & 0 deletions pokemongo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# poke-mongo

Docker

docker-compose up --build

Mongoosejs

https://mongoosejs.com/docs/api.html

Carga excel API

route: /api/carga
64 changes: 64 additions & 0 deletions pokemongo/app/Controllers/CargaController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict'

const Pokemon = require('../Models/Pokemon')
const fs = require('fs')
const excelToJson = require('convert-excel-to-json')

class CargaController {
async store (req, res, next) {
const file = req.file

try {
const arr = excelToJson({
source: fs.readFileSync(file.path), // fs.readFileSync return a Buffer
header: {
rows: 1
},
columnToKey: {
A: 'row',
B: 'name',
C: 'pokedex_number',
D: 'img_name',
E: 'generation',
F: 'evolution_stage',
G: 'evolved',
H: 'family_id',
I: 'cross_gen',
J: 'type_1',
K: 'type_2',
L: 'wheather_1',
M: 'wheather_2',
N: 'stat_total',
O: 'atk',
P: 'def',
Q: 'sta',
R: 'legendary',
S: 'aquireable',
T: 'spawns',
U: 'regional',
V: 'raidable',
W: 'hatchable',
X: 'shiny',
Y: 'nest',
Z: 'new',
AA: 'not_Gettable',
AB: 'futute_evolve',
AC: 'forty',
AD: 'thirty_nine'
}
})

for (const i of arr.Sheet1) {
await Pokemon.create(i)
}

return res.json({
success: true
})
} catch (err) {
return next(err)
}
}
}

module.exports = new CargaController()
74 changes: 74 additions & 0 deletions pokemongo/app/Controllers/PokemonController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict'

const Pokemon = require('../Models/Pokemon')
const fs = require('fs')
const excelToJson = require('convert-excel-to-json')

class PokemonController {
async index (req, res) {
const perPage = 10
const page = req.params.page || 1

const pokemons = await Pokemon.find()
.where(req.body)
.skip((perPage * page) - perPage)
.limit(perPage)

return res.json(pokemons)
}

async store (req, res, next){
try {
const pokemon = await Pokemon.create(req.body)

return res.json(pokemon)
} catch (err) {
return next(err)
}
}

async show (req, res) {
try {
const pokemon = await Pokemon.findOne({
_id: req.params.id
})

res.send({ pokemon })
} catch (err) {
return next(err)
}
}

async update (req, res) {
try {
const pokemon = await Pokemon.findOne({
_id: req.params.id
})

await pokemon.update(req.body)

return res.json({
success: true
})
} catch (err) {
return next(err)
}
}

async destroy (req, res) {
try {
await Pokemon.findOneAndDelete({
_id: req.params.id
})

return res.json({
success: true
})
} catch (err) {
return next(err)
}

}
}

module.exports = new PokemonController()
22 changes: 22 additions & 0 deletions pokemongo/app/Exceptions/ApiException.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

class ApiException extends Error {
constructor (status, message) {
super()
this.status = status
this.message = message
}
}

const handleError = (err, res) => {
const { status, message } = err
res.status(status || 400).json({
status,
message
})
}

module.exports = {
ApiException,
handleError
}
Loading