Skip to content

Jay leach #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2020
Merged
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
12 changes: 11 additions & 1 deletion api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const helmet = require('helmet');
const authenticate = require('../auth/authenticate-middleware.js');
const authRouter = require('../auth/auth-router.js');

const berryRouter = require('../berries/berryRouter.js');
const itemRouter = require('../items/itemRouter.js');
const machineRouter = require('../machines/machineRouter.js');
const pokemonRouter = require('../pokemon/pokemonRouter.js');

const server = express();

server.use(helmet());
Expand All @@ -15,6 +20,11 @@ server.get('/', (req, res) => {
res.status(200).json({ test: "LISTENING" })
})

server.use('/api/auth', authRouter);
server.use('/api/auth', authRouter); // For the trainer

server.use('/api/berries', authenticate, berryRouter); // For the berries
server.use('/api/items', authenticate, itemRouter); // For the items
server.use('/api/machines', authenticate, machineRouter); // For the machines
server.use('/api/pokemon', authenticate, pokemonRouter); // For the pokemon

module.exports = server;
Empty file added berries/berryModel.js
Empty file.
Empty file added berries/berryRouter.js
Empty file.
82 changes: 78 additions & 4 deletions database/migrations/20200305182952_create_tables.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,88 @@
exports.up = function(knex) {
return knex.schema.createTable('users', tbl => {
tbl.increments();
tbl.string('username', 128).unique().notNullable();
tbl.string('password', 256).notNullable();
tbl.string('user_type');
})

.createTable('items', tbl => {
tbl.string('name').notNullable();
tbl.integer('id');
tbl.integer('cost');
tbl.integer('user_id')
.unsigned()
.notNullable()
references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('RESTRICT');
tbl.integer('total_count');
tbl.integer('count').defaultTo(0);
})

.createTable('machines', tbl => {
tbl.string('name').notNullable();
tbl.integer('id');
tbl.integer('user_id')
.unsigned()
.notNullable()
references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('RESTRICT');
tbl.integer('count').defaultTo(0);
tbl.string('mega-punch').notNullable();
})

.createTable('berries', tbl => {
tbl.string('name').notNullable();
tbl.integer('id');
tbl.integer('user_id')
.unsigned()
.notNullable()
references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('RESTRICT');
tbl.integer('size');
tbl.integer('smoothness');
tbl.integer('naturalGiftPower');
tbl.integer('soilDryness');
tbl.integer('growthTime');
tbl.integer('maxHarvest');
})

tbl.increments();
tbl.string('username', 128).unique().notNullable();
tbl.string('password', 256).notNullable();
tbl.string('user_type');
.createTable('pokemon', tbl => {
tbl.integer('id');
tbl.string('name').notNullable();
tbl.string('img').notNullable();
tbl.integer('height');
tbl.integer('weight');
tbl.specificType('types', 'text ARRAY');
tbl.integer('speed');
tbl.integer('specialAttack');
tbl.integer('specialDefense');
tbl.integer('defense');
tbl.integer('attack');
tbl.integer('hp');
tbl.specificType('abilities', 'text ARRAY');
tbl.specificType('moves', 'text ARRAY');
tbl.integer('user_id')
.unsigned()
.notNullable()
references('id')
.inTable('users')
.onUpdate('CASCADE')
.onDelete('RESTRICT');
})
};

exports.down = function(knex) {
return knex.schema
.dropTableIfExists('pokemon')
.dropTableIfExists('berries')
.dropTableIfExists('machines')
.dropTableIfExists('items')
.dropTableIfExists('users')
};
18 changes: 17 additions & 1 deletion database/seeds/05-pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ exports.seed = function (knex) {
return knex('').truncate()
.then(function () {
return knex('').insert([
{}
{
id: 1,
name: 'bulbasaur',
img: 'https://img.pokemondb.net/sprites/black-white/anim/normal/bulbasaur.gif',
height: 7,
weight: 69,
types: ['poison', 'grass'],
speed: 45,
specialAttack: 65,
specialDefense: 65,
defense: 45,
attack: 49,
hp: 45,
abilities: ['chlorophyll', 'overgrow'],
moves: ['razor-wind', 'swords-dance', 'cut', 'bind'],
user_id: 1
}
]);
});
};
Empty file added items/itemModel.js
Empty file.
Empty file added items/itemRouter.js
Empty file.
Empty file added machines/machineModel.js
Empty file.
Empty file added machines/machineRouter.js
Empty file.
Empty file added pokemon/pokemonModel.js
Empty file.
Empty file added pokemon/pokemonRouter.js
Empty file.