Skip to content

Commit 28aa676

Browse files
committed
Pokemon and Machines router, model, seed, and migration done
1 parent f9097c5 commit 28aa676

File tree

11 files changed

+247
-276
lines changed

11 files changed

+247
-276
lines changed

03-machines.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

05-pokemon.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

api/server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const authRouter = require('../auth/auth-router.js');
77

88
const berryRouter = require('../berries/berryRouter.js');
99
const itemRouter = require('../items/itemRouter.js');
10-
// const machineRouter = require('../machines/machineRouter.js');
11-
// const pokemonRouter = require('../pokemon/pokemonRouter.js');
10+
const machineRouter = require('../machines/machineRouter.js');
11+
const pokemonRouter = require('../pokemon/pokemonRouter.js');
1212

1313
const server = express();
1414

@@ -24,7 +24,7 @@ server.use('/api/auth', authRouter); // For the trainer
2424

2525
server.use('/api/berries', berryRouter); // For the berries
2626
server.use('/api/items', itemRouter); // For the items
27-
// server.use('/api/machines', machineRouter); // For the machines
28-
// server.use('/api/pokemon', pokemonRouter); // For the pokemon
27+
server.use('/api/machines', machineRouter); // For the machines
28+
server.use('/api/pokemon', pokemonRouter); // For the pokemon
2929

3030
module.exports = server;

database/auth.db3

8 KB
Binary file not shown.

database/migrations/20200305182952_create_tables.js

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,65 @@ exports.up = function(knex) {
2222
tbl.integer('count').defaultTo(0);
2323
})
2424

25-
// .createTable('machines', tbl => {
26-
// tbl.increments();
27-
// tbl.string('name').notNullable();
28-
// tbl.integer('pokeid');
29-
// tbl.integer('user_id')
30-
// .unsigned()
31-
// .notNullable()
32-
// .references('pokeid')
33-
// .inTable('users')
34-
// .onUpdate('CASCADE')
35-
// .onDelete('RESTRICT');
36-
// tbl.integer('count').defaultTo(0);
37-
// tbl.string('mega-punch').notNullable();
38-
// })
39-
//
40-
.createTable('berries', tbl => {
41-
tbl.increments();
42-
tbl.string('name').notNullable();
43-
tbl.integer('pokeid');
44-
tbl.integer('user_id')
45-
.unsigned()
46-
.notNullable()
47-
.references('pokeid')
48-
.inTable('users')
49-
.onUpdate('CASCADE')
50-
.onDelete('RESTRICT');
51-
tbl.integer('size');
52-
tbl.integer('smoothness');
53-
tbl.integer('naturalGiftPower');
54-
tbl.integer('soilDryness');
55-
tbl.integer('growthTime');
56-
tbl.integer('maxHarvest');
57-
tbl.integer('count').defaultTo(0);
58-
})
59-
//
60-
// .createTable('pokemon', tbl => {
61-
// tbl.increments();
62-
// tbl.integer('pokeid');
63-
// tbl.string('name').notNullable();
64-
// tbl.string('img').notNullable();
65-
// tbl.integer('height');
66-
// tbl.integer('weight');
67-
// tbl.specificType('types', 'text ARRAY');
68-
// tbl.integer('speed');
69-
// tbl.integer('specialAttack');
70-
// tbl.integer('specialDefense');
71-
// tbl.integer('defense');
72-
// tbl.integer('attack');
73-
// tbl.integer('hp');
74-
// tbl.specificType('abilities', 'text ARRAY');
75-
// tbl.specificType('moves', 'text ARRAY');
76-
// tbl.integer('user_id')
77-
// .unsigned()
78-
// .notNullable()
79-
// .references('pokeid')
80-
// .inTable('users')
81-
// .onUpdate('CASCADE')
82-
// .onDelete('RESTRICT');
83-
// })
25+
.createTable('machines', tbl => {
26+
tbl.increments();
27+
tbl.string('name').notNullable();
28+
tbl.integer('pokeid');
29+
tbl.integer('user_id')
30+
.unsigned()
31+
.notNullable()
32+
.references('pokeid')
33+
.inTable('users')
34+
.onUpdate('CASCADE')
35+
.onDelete('RESTRICT');
36+
tbl.integer('count').defaultTo(0);
37+
tbl.string('move').notNullable();
38+
})
39+
40+
.createTable('berries', tbl => {
41+
tbl.increments();
42+
tbl.string('name').notNullable();
43+
tbl.integer('pokeid');
44+
tbl.integer('user_id')
45+
.unsigned()
46+
.notNullable()
47+
.references('pokeid')
48+
.inTable('users')
49+
.onUpdate('CASCADE')
50+
.onDelete('RESTRICT');
51+
tbl.integer('size');
52+
tbl.integer('smoothness');
53+
tbl.integer('naturalGiftPower');
54+
tbl.integer('soilDryness');
55+
tbl.integer('growthTime');
56+
tbl.integer('maxHarvest');
57+
tbl.integer('count').defaultTo(0);
58+
})
59+
60+
.createTable('pokemon', tbl => {
61+
tbl.increments();
62+
tbl.integer('pokeid');
63+
tbl.string('name').notNullable();
64+
tbl.string('img').notNullable();
65+
tbl.integer('height');
66+
tbl.integer('weight');
67+
tbl.specificType('types', 'text ARRAY');
68+
tbl.integer('speed');
69+
tbl.integer('specialAttack');
70+
tbl.integer('specialDefense');
71+
tbl.integer('defense');
72+
tbl.integer('attack');
73+
tbl.integer('hp');
74+
tbl.specificType('abilities', 'text ARRAY');
75+
tbl.specificType('moves', 'text ARRAY');
76+
tbl.integer('user_id')
77+
.unsigned()
78+
.notNullable()
79+
.references('pokeid')
80+
.inTable('users')
81+
.onUpdate('CASCADE')
82+
.onDelete('RESTRICT');
83+
})
8484
};
8585

8686
exports.down = function(knex) {

database/seeds/03-machines.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exports.seed = function (knex) {
2+
return knex('machines').truncate()
3+
.then(function () {
4+
return knex('machines').insert([
5+
{
6+
name: 'tm01',
7+
pokeid: 2,
8+
user_id: 1,
9+
count: 1,
10+
move: 'mega-punch'
11+
}
12+
]);
13+
});
14+
};

database/seeds/05-pokemon.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exports.seed = function (knex) {
2+
return knex('pokemon').truncate()
3+
.then(function () {
4+
return knex('pokemon').insert([
5+
{
6+
pokeid: 1,
7+
name: 'bulbasaur',
8+
img: 'https://img.pokemondb.net/sprites/black-white/anim/normal/bulbasaur.gif',
9+
height: 7,
10+
weight: 69,
11+
types: ['poison', 'grass'],
12+
speed: 45,
13+
specialAttack: 65,
14+
specialDefense: 65,
15+
defense: 45,
16+
attack: 49,
17+
hp: 45,
18+
abilities: ['chlorophyll', 'overgrow'],
19+
moves: ['razor-wind', 'swords-dance', 'cut', 'bind'],
20+
user_id: 1
21+
}
22+
]);
23+
});
24+
};

machines/machineModel.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
const db = require('../database/dbConfig');
22

33
module.exports = {
4-
getItems,
5-
getItemsById,
6-
addItem,
7-
getItemFilter,
8-
updateItem,
9-
deleteItem,
10-
updateItemCount
4+
getMachines,
5+
getMachinesById,
6+
addMachine,
7+
getMachinesFilter,
8+
updateMachine,
9+
deleteMachine,
10+
updateMachineCount
1111
};
1212

13-
function getItems() {
14-
return db('items');
13+
function getMachines() {
14+
return db('machines');
1515
}
1616

17-
function addItem(post) {
18-
return db('items as i')
17+
function addMachine(post) {
18+
return db('machines as m')
1919
.insert(post)
2020
.then(ids => {
21-
console.log('ADD ITEM', ids)
21+
console.log('ADD MACHINE', ids)
2222
const [id] = ids;
23-
return getItemsById(id);
23+
return getMachinesById(id);
2424
})
2525
}
2626

27-
function getItemsById(id) {
28-
return db('items')
27+
function getMachinesById(id) {
28+
return db('machines')
2929
.select('*')
3030
.where({id})
3131
.first()
3232
}
3333

34-
async function updateItem(id, changes) {
35-
await db('classes')
34+
async function updateMachine(id, changes) {
35+
await db('machines')
3636
.where({id})
3737
.update(changes)
3838

39-
return getClassesById(id);
39+
return getMachinesById(id);
4040
}
4141

42-
async function updateItemCount(id, changes) {
43-
await db('items')
42+
async function updateMachineCount(id, changes) {
43+
await db('machines')
4444
.where({id})
4545
.update(changes)
4646

47-
return db('items')
47+
return db('machines')
4848
.select('count')
4949
.where({id})
5050
.first()
5151
}
5252

53-
function deleteItem(id) {
54-
return db('items')
53+
function deleteMachine(id) {
54+
return db('machines')
5555
.where('id', id)
5656
.delete()
5757
}
5858

59-
function getItemsFIlter(filter) {
60-
return db('items')
59+
function getMachinesFilter(filter) {
60+
return db('machines')
6161
.select('*')
6262
.where('user_id', filter)
6363
}

0 commit comments

Comments
 (0)