diff --git a/.env-example b/.env-example deleted file mode 100644 index b8517ec..0000000 --- a/.env-example +++ /dev/null @@ -1,9 +0,0 @@ -# *** Server *** -PORT=3000 - -# *** Database *** -DATABASE_URL={copy from terminal: `heroku config:get DATABASE_URL`} -PGSSLMODE=require - -# *** API KEYS *** - diff --git a/data/animals.js b/data/animals.js deleted file mode 100644 index fce3e93..0000000 --- a/data/animals.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = [ - { - name: 'bessie', - cool_factor: 3, - }, - { - name: 'jumpy', - cool_factor: 4, - }, - { - name: 'spot', - cool_factor: 10, - } -]; diff --git a/data/create-tables.js b/data/create-tables.js index 24c7acd..fe7e736 100644 --- a/data/create-tables.js +++ b/data/create-tables.js @@ -11,19 +11,50 @@ async function run() { await client.connect(); // run a query to create tables + // Wow!! Look at this data model! So much complexity. My only concern: is it necessary to track the loggedinuser in its own table? await client.query(` CREATE TABLE users ( id SERIAL PRIMARY KEY, email VARCHAR(256) NOT NULL, - hash VARCHAR(512) NOT NULL - ); - CREATE TABLE animals ( - id SERIAL PRIMARY KEY NOT NULL, + hash VARCHAR(512) NOT NULL, + user_ship VARCHAR(512) + + ); + CREATE TABLE loggedinuser ( + id SERIAL PRIMARY KEY, name VARCHAR(512) NOT NULL, - cool_factor INTEGER NOT NULL, + score INTEGER NOT NULL, owner_id INTEGER NOT NULL REFERENCES users(id) + ); + + CREATE TABLE locations ( + id SERIAL PRIMARY KEY NOT NULL, + location_name VARCHAR(512) NOT NULL, + location_type VARCHAR(512) NOT NULL, + location_image VARCHAR(512) NOT NULL, + location_description VARCHAR(512) NOT NULL, + event_id INTEGER NOT NULL UNIQUE + ); + CREATE TABLE events ( + id SERIAL PRIMARY KEY NOT NULL, + planet_id INTEGER REFERENCES locations(event_id), + event_name VARCHAR(512) NOT NULL, + event_image VARCHAR(1000) NOT NULL, + event_description VARCHAR(2000) NOT NULL, + event_choices VARCHAR(5000) ARRAY NOT NULL + ); + CREATE TABLE shipchoices ( + id SERIAL PRIMARY KEY NOT NULL, + ship_name VARCHAR(512) NOT NULL, + ship_fuel INTEGER NOT NULL, + ship_hull INTEGER NOT NULL, + base_combat INTEGER NOT NULL, + base_diplomacy INTEGER NOT NULL, + base_science INTEGER NOT NULL, + used_item_slots INTEGER NOT NULL, + max_item_slots INTEGER NOT NULL ); - `); + `); // Generally, the SQL standard would have put ship_choices in snake case console.log('create tables complete', getEmoji(), getEmoji(), getEmoji()); } diff --git a/data/drop-tables.js b/data/drop-tables.js index 712386b..d5215bb 100644 --- a/data/drop-tables.js +++ b/data/drop-tables.js @@ -10,7 +10,10 @@ async function run() { await client.query(` DROP TABLE IF EXISTS users CASCADE; - DROP TABLE IF EXISTS animals; + DROP TABLE IF EXISTS locations CASCADE; + DROP TABLE IF EXISTS events; + DROP TABLE IF EXISTS shipchoices; + DROP TABLE IF EXISTS loggedinuser; `); console.log(' drop tables complete', getEmoji(), getEmoji(), getEmoji()); diff --git a/data/events.js b/data/events.js new file mode 100644 index 0000000..b44c965 --- /dev/null +++ b/data/events.js @@ -0,0 +1,342 @@ +module.exports = [ + { + event_name: 'Desert Crops', + planet_id: 1, + event_image: 'https://kevishere.files.wordpress.com/2017/12/pr-crops.jpg?w=648', + event_description: 'As you land your ship you see some of the of the Alien farmers from this planet screaming at you. You quickly realize youve landed in the center of there crops! They seem really upset at your actions', + event_choices: [{ + choice_description: 'Attempt to explain the situation to the indigenous people.', + roll_needed: 5, + roll_type: 'diplomacy', + result: { + sucess: 'They reluctantly forgive you and allow you to leave the planet peacefully.', + failure: 'They scream and start banging on your ship and kick you off planet!' + }, + rewards: { + success_fuel: 0, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } + }, + { + choice_description: 'Notice things are getting out of hand and prepare to handle the situation with force.', + roll_needed: 6, + roll_type: 'combat', + result: { + sucess: 'You power on your ships weapons and defend yourself against the alien farmers. After dealing with the Alien farmers you gather the supplies they had on planet..... you had to defend yourself, right?', + failure: 'You power on your ships weapons and attempt to defend yourself. You are quickly overpowered by the alien farmers as they steal your supplies. Luckily you break away and are able to leave planet before they can damage your ship any further.' + }, + rewards: { + success_fuel: 1, + success_credit: 2, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } }, + { + choice_description: 'Realize your mistake and attempt to use your ships facilities to correct the problem.', + roll_needed: 5, + roll_type: 'science', + result: { + sucess: 'They seem wary at first, but you create some advanced farming tools from your ship. The Alien farmers are ecstatic and allow you to stay the night in there village!', + failure: 'The tools you provide quickly fall apart and the Alien farmers scream and kick you off planet!' + }, + rewards: { + success_fuel: 2, + success_credit: -1, + success_health: 2, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } } + ] + }, + { + event_name: 'Oxygen Depletion', + planet_id: 2, + event_image: 'https://66.media.tumblr.com/8c3d6ffed9be5b4ec120c6665b177084/tumblr_nnja23kKnc1s0eroxo1_640.jpg', + event_description: 'As you are gliding down to the planet a winged creature of some sort slams into your ship and causes you to crash into the surface.', + event_choices: [{ + //add a second choice for combat + choice_description: 'As you look over your ship you see that your life support system has been damaged. You put your space suit on and head outside to attempt to fix the damage.', + roll_needed: 4, + roll_type: 'science', + result: { + sucess: 'You finish the repairs on your life support system in time and even learn some interesting information from the damage.', + failure: 'You take way to long to finish the repairs and have to rest on planet before continuing your journey.' + }, + rewards: { + success_fuel: 0, + success_credit: 1, + success_health: 0, + failure_fuel: 0, + failure_credit: -1, + failure_health: -1 + } } + ] + }, + + { + event_name: 'Risk and Reward', + planet_id: 3, + event_image: 'https://images.theconversation.com/files/157841/original/image-20170222-1364-hr3hcv.jpg?ixlib=rb-1.1.0&q=45&auto=format&w=496&fit=clip', + event_description: 'You land your ship on planet to gather any supplies available to help on your journey. Nothing is setting off the scanner around your ship. You lower the bay door and walk onto the cold hard surface of this planet with your weapons. You find some minerals that would be worth a good amount of credits. You start to gather these materials when you hear a low rumble approaching you.', + event_choices: [{ + choice_description: 'You spin around with your rifle and attempt to defend yourself from the large apex-predator!', + roll_needed: 6, + roll_type: 'combat', + result: { + sucess: 'You unload your rifles clip into the apex predator before it is able to close the distance. The rare minerals are yours!', + failure: 'The apex predator leaps into the air and lands next to you slashing and biting at your body. You get into a prolonged fight but come out on top. Sadly the apex predator did some damage in return.' + }, + rewards: { + success_fuel: 0, + success_credit: 8, + success_health: 0, + failure_fuel: 0, + failure_credit: 3, + failure_health: -2, + } } + ] + }, + + { + event_name: 'Ancient City', + planet_id: 4, + event_image: 'https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/cb63c2f9-bbd6-498a-902d-7627d6d48a05/dakedq-3ee895c6-5c3a-4c12-bd16-0f2ee6ecdc11.jpg/v1/fill/w_798,h_515,q_75,strp/alien_city_by_arrowfire_dakedq-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD01MTUiLCJwYXRoIjoiXC9mXC9jYjYzYzJmOS1iYmQ2LTQ5OGEtOTAyZC03NjI3ZDZkNDhhMDVcL2Rha2VkcS0zZWU4OTVjNi01YzNhLTRjMTItYmQxNi0wZjJlZTZlY2RjMTEuanBnIiwid2lkdGgiOiI8PTc5OCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.6muSyo7qL4gNrGRM_roLX8twtkab_tnCCNwuv4vY-R8', + event_description: 'You land your ship on the outskirts of the ancient abandoned city to see what you can find.', + event_choices: [{ + choice_description: 'You spot a local native looking at you and your ship curiously. It seems the Aliens of this planet have lost whatever technological advancements they had. You decide to introduce yourself and attempt some diplomacy.', + roll_needed: 6, + roll_type: 'diplomacy', + result: { + sucess: 'The alien leads you to his tribe and shows you there treasures. They seem to value food, strong metals, and things that help them hunt and protect themselves. You offer some of your tools and an advanced heater that never runs out of power. They are extremely grateful and offer you some old technology.', + failure: 'You attempt to communicate with the Alien. They howl and run off into the dense city and lose you. You look around for any supplies but find nothing of value, such a waste of fuel. Time to move on.' + }, + rewards: { + success_fuel: 2, + success_credit: 2, + success_health: 0, + failure_fuel: -1, + failure_credit: 0, + failure_health: 0, + } + }, + { + choice_description: 'You decide to search the ancient abandoned city for any useful supplies.', + roll_needed: 5, + roll_type: 'science', + result: { + sucess: 'You use your science tools at your disposal to scan the surrounding buildings. Your scanner goes off and you find a old research laboratory with a cacheful of supplies!', + failure: 'It seems the city has already been ravaged by scavengers. Time to move on.' + }, + rewards: { + success_fuel: 1, + success_credit: 3, + success_health: 0, + failure_fuel: 0, + failure_credit: -1, + failure_health: 0, + } } + ] + }, + { + event_name: 'FrostBite?', + planet_id: 5, + event_image: 'https://i.pinimg.com/originals/55/c4/89/55c4892d99b434106e05ee892e6b54de.jpg', + event_description: 'You land your ship on the Icy planet hoping to find something useful on your journeys.', + event_choices: [{ + choice_description: 'You notice a large shape encased in ice a few hundred yards from your position.', + roll_needed: 7, + roll_type: 'science', + result: { + sucess: 'With your equipment in hand you head over to the frozen shape. You see its a old satelite from a long time ago. You melt the ice and recover what you can from it.', + failure: 'With your equipment in hand you head over to the frozen shape. You see its a old satelite. Sadly you are unable to free it from its cold prison. When you return to your ship you see its damaged from the blizzard. Time to move on.' + }, + rewards: { + success_fuel: 1, + success_credit: 1, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } + }, + { + choice_description: 'You see behind you there is a rock formation with a cave entrance. Perhaps there are some minerals inside you could use.', + roll_needed: 5, + roll_type: 'combat', + result: { + sucess: 'As you enter the cave complex you quickly realize you are not alone! You pull your flare out and light it seeing a large multi eyed creature scurrying toward you. You turn on your blaster and scare it away with a warning shot. You quickly find some minerals that will help your journey and decide to leave.', + failure: 'As you enter the cave complex you do not notice the creature crawling behind you. It quickly overwhelms you and tears into your space suit. You run out of the cave hoping you can make it to your ship in time!' + }, + rewards: { + success_fuel: 1, + success_credit: 1, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -2, + } } + ] + }, + { + event_name: 'Do not touch the tar!', + planet_id: 6, + event_image: 'https://i.pinimg.com/originals/92/ee/d8/92eed8171d698f4d2aa1bb94ee24e350.jpg', + event_description: 'You land your ship on Xivon III. It seems mostly deserted and has a foul smell about it. The large pools of what you are guessing is tar keep bubbling...wait is the tar moving toward you?', + event_choices: [{ + choice_description: 'You are shocked as the tar comes sliming over toward you! You power up your ships weapons and shields and attempt to fight the entity off.', + roll_needed: 5, + roll_type: 'combat', + result: { + sucess: 'You quickly turn your ships weapons on the entity and shoot it back into the tar pit. You quickly notice more and more of these entitys are coming out of the surrounding pits. Time to move on!', + failure: 'You quickly turn your ships weapons on the entity but miss your first few shots. Your ships alarms start to blare as its eating into your hull. You quickly power on the thrusters and take off into space. Time to check the damage.' + }, + rewards: { + success_fuel: 0, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -2, + } + }, + { + choice_description: 'You scream and run as the tar comes sliming over toward you. You enter your computers systems to prepare for the creature.', + roll_needed: 5, + roll_type: 'science', + result: { + sucess: 'You enter your ships systems to change the frequency of your shields. If this is anything like Earth you know exactly what to do! You hear the entity scream as it attempts to attack your ship. It rolls its way back into the pit and you take the oppurtunity to leave this place.', + failure: 'The entity slams into your ships and your alarms start to blare as its eating into your hull. You quickly power on the thrusters and take off into space. Time to check the damage.' + }, + rewards: { + success_fuel: 0, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -2, + } } + ] + }, + { + event_name: 'Harvesting Gas', + planet_id: 7, + event_image: 'https://vignette.wikia.nocookie.net/warframe/images/e/ee/Plains_of_Eidolon_at_Day_%282%29.jpg/revision/latest?cb=20180717001626', + event_description: 'You land your ship on Noxabas I and take in the scenery. It seems these large fissures are realising some type of gas. It could probably help fuel your ship.', + event_choices: [{ + choice_description: 'You see in the distance a alien looking facility. Perhaps they are friendly?', + roll_needed: 5, + roll_type: 'diplomacy', + result: { + sucess: 'You approach the facility and a native of this planet steps out of the doors to meet you. You exchange words and they agree to let you take some of the gas from there facility.', + failure: 'You approach the facility and a native of this planet steps out of the doors to meet you. You must have said something very upsetting as they seems to be calling to there comrades in the building. Time to move on!' + }, + rewards: { + success_fuel: 1, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: 0, + } + }, + { + choice_description: 'You see a fissure that is perfectly positioned for your ships harvester. Perhaps you can work the system to your advantage.', + roll_needed: 7, + roll_type: 'science', + result: { + sucess: 'You hover your ship over the fissure and start working at your terminal. After some time and a large amount of luck you are able to extract the gas into your ships reserve tank.', + failure: 'You hover your ship over the fissure and start working at your terminal. It seems you are unable to properly break down the gasses composition and it leaks into your ships systems. Time to move on.' + }, + rewards: { + success_fuel: 1, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } + }, + { + choice_description: 'You see in the distance a alien looking facility harvesting gas. A facility that advanced must have things worth taking.', + roll_needed: 8, + roll_type: 'combat', + result: { + sucess: 'You grab your weapons and head over to the facility. As you enter the facility you see multiple workers harvesting gas and placing them into energy capsules. You yell a few commands and they all back away. You fill your bag full of these capsules and make it back to your ship. Time to move on.', + failure: 'You grab your weapons and head over to the facility. As you enter the facility you get into a fire fight with some of the guards of the building. You quickly escape back to your ship and start to take off. They take some shots which damage your hull in your lift off.' + }, + rewards: { + success_fuel: 2, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -1, + } } + ] + }, + { + event_name: 'I feel like this has happened in a movie before...', + planet_id: 8, + event_image: 'https://i.redd.it/erbux89v0lx11.jpg', + event_description: 'You land on Yoraporr I and start to gather supplies. Did something just shimmer in that tree?', + event_choices: [{ + choice_description: 'Its probably nothing, just in case though maybe I should introduce myself.', + roll_needed: 10, + roll_type: 'diplomacy', + result: { + sucess: 'You call out to the tree and declare your intentions. A very long uncomfortable moment passes then something jumps out of the tree. You watch as it appears before your eyes. It was invisible! It offers you a small bag and then dissapears into the deep jungle. You examine the bag and see its full of supplies. Time to move on!', + failure: 'You call out to the tree and declare your intentions. After a short amount of time 3 red dots start to appear on your body. You quickly run toward your ship as the being starts to unleash energy blasts. You attempt to leave planet as its shooting at your ship.' + }, + rewards: { + success_fuel: 1, + success_credit: 1, + success_health: 1, + failure_fuel: 0, + failure_credit: 0, + failure_health: -3, + } + }, + { + choice_description: 'You slowly pull out your weapon acting like you do not notice it inside the tree.', + roll_needed: 9, + roll_type: 'combat', + result: { + sucess: 'You spin around and take a shot at the being inside the tree. It lets out a guttural noise and you see 3 red dots appear on your chest as it unleashes a energy blast. You quickly dodge out of the way and keep shooting. It goes quite for sometime and you finally notice you landed one of your shots. You take what you can off of its invisble corpse and leave.', + failure: 'You spin around and take a shot at the being inside the tree. It lets out a guttural noise and you see 3 red dots appear on your chest as it unleashes energy blasts. You can no longer pinpoint its position and you attempt to flee from the planet.' + }, + rewards: { + success_fuel: 1, + success_credit: 2, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -2, + } + }, + { + choice_description: 'You pull out your scanner and point it at the tree...what could it be?', + roll_needed: 6, + roll_type: 'science', + result: { + sucess: 'You read your scanner and see a invisible large humanoid shape looking at you from the tree. You scream and run into your ship and take off before it can hunt you.', + failure: 'You read your scanner but it seems to be malfunctioning. Theres no way theres an invisble large humanoid there. A huge explosion knocks you off your feet as the creature lets out a guttural roar. You run into your ship and attempt to take off before it can cause more damage!' + }, + rewards: { + success_fuel: 0, + success_credit: 0, + success_health: 0, + failure_fuel: 0, + failure_credit: 0, + failure_health: -2, + } } + ] + } +]; + diff --git a/data/load-seed-data.js b/data/load-seed-data.js index 55f62b6..83a5137 100644 --- a/data/load-seed-data.js +++ b/data/load-seed-data.js @@ -1,7 +1,9 @@ const client = require('../lib/client'); // import our seed data: -const animals = require('./animals.js'); +const locations = require('./locations.js'); const usersData = require('./users.js'); +const events = require('./events.js'); +const shipChoices = require('./shipchoices.js'); const { getEmoji } = require('../lib/emoji.js'); run(); @@ -11,6 +13,8 @@ async function run() { try { await client.connect(); + + const users = await Promise.all( usersData.map(user => { return client.query(` @@ -21,16 +25,35 @@ async function run() { [user.email, user.hash]); }) ); - const user = users[0].rows[0]; + + await Promise.all( + locations.map(location => { + return client.query(` + INSERT INTO locations (location_name, location_type,location_image, location_description, event_id) + VALUES ($1, $2, $3, $4, $5); + `, + [location.location_name, location.location_type, location.location_image, location.location_description, location.event_id]); + }) + ); + + await Promise.all( + events.map(event => { + return client.query(` + INSERT INTO events (planet_id, event_name, event_image, event_description, event_choices) + VALUES ($1, $2, $3, $4, $5); + `, + [event.planet_id, event.event_name, event.event_image, event.event_description, event.event_choices]); + }) + ); await Promise.all( - animals.map(animal => { + shipChoices.map(ship => { return client.query(` - INSERT INTO animals (name, cool_factor, owner_id) - VALUES ($1, $2, $3); + INSERT INTO shipchoices (ship_name, ship_fuel, ship_hull, base_combat, base_diplomacy, base_science, used_item_slots, max_item_slots) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8); `, - [animal.name, animal.cool_factor, user.id]); + [ship.ship_name, ship.ship_fuel, ship.ship_hull, ship.base_combat, ship.base_diplomacy, ship.base_science, ship.used_item_slots, ship.max_item_slots]); }) ); diff --git a/data/locations.js b/data/locations.js new file mode 100644 index 0000000..71c47db --- /dev/null +++ b/data/locations.js @@ -0,0 +1,60 @@ +module.exports = [ + { + location_name: 'Gilles C11Y', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2018/08/08/20/23/planet-3593060_960_720.jpg', + location_description: 'Gilles C11Y is a desert of smooth rocks. Spires of sharp stone interrupt the otherwise flat terrain. There are groups of tall, dark orange stalks everywhere. There seems to be large burrows throughout the seemingly deserted planet.', + event_id: 1 + }, + + { + location_name: 'Sulia V', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2017/07/11/21/21/planet-2495089_960_720.jpg', + location_description: 'Dense forests of brown plants cover Sulia V. Large water-filled caves are present just beneath the surface. The geological record shows irregular periods where, for unknown reasons, all oxygen vanished from the atmosphere.', + event_id: 2 + }, + { + location_name: 'Ipelup VI', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2020/05/04/14/55/sci-fi-5129504_960_720.jpg', + location_description: 'A planet-wide, deep ocean. The planet is home to extremely dangerous apex predators. The stone of the planetary crust is unusually dense and hard.', + event_id: 3 + }, + + { + location_name: 'Selelup II', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2018/08/12/00/48/planet-3599887_960_720.jpg', + location_description: 'Selelup II is a rocky desert type planet that is lit by a gentle sun. Spires of sharp stone interrupt the otherwise flat eterrain. There are signs of a once foreign colony, but now it seems abandoned. There is no water on this now deserted planet.', + event_id: 4 + }, + { + location_name: 'Laravim VI', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2015/06/26/18/48/mercury-822825_960_720.png', + location_description: 'Laravim VI is an icy desert. Towering columns of hexagonal black stone. Some local plants hover in mid-air, held aloft by gas bags.', + event_id: 5 + }, + { + location_name: 'Xivon III', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2016/04/13/06/40/mars-1326108_960_720.jpg', + location_description: 'Xivon III is covered in black mud and small rivulets. Deep canyons cut into the planets crust. The local plant life takes the shape of small blue bubbles.', + event_id: 6 + }, + { + location_name: 'Noxabas I', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2017/11/16/09/32/planet-2953871_960_720.png', + location_description: 'Noxabas I is covered in grey mud and small rivulets. Noxious gases erupt from deep fissures. There are massive flowers in all kinds of colors, sitting atop thick dark green stems.', + event_id: 7 + }, + { + location_name: 'Yoraporr I', + location_type: 'Planet', + location_image: 'https://cdn.pixabay.com/photo/2018/02/12/21/03/planet-3149121_960_720.jpg', + location_description: 'Yoraporr I is covered in dense jungles of giant dark green geodesic domes cover Yoraporr I. The land is a maze of steep valleys.', + event_id: 8 + }, +]; diff --git a/data/shipchoices.js b/data/shipchoices.js new file mode 100644 index 0000000..7ae6c2b --- /dev/null +++ b/data/shipchoices.js @@ -0,0 +1,32 @@ +module.exports = [ + { + ship_name: 'The Reach', + ship_fuel: 4, + ship_hull: 6, + base_combat: 1, + base_diplomacy: 3, + base_science: 2, + used_item_slots: 0, + max_item_slots: 3, + }, + { + ship_name: 'The Avenger', + ship_fuel: 4, + ship_hull: 6, + base_combat: 3, + base_diplomacy: 2, + base_science: 1, + used_item_slots: 0, + max_item_slots: 3 + }, + { + ship_name: 'The Icarus', + ship_fuel: 4, + ship_hull: 6, + base_combat: 1, + base_diplomacy: 2, + base_science: 3, + used_item_slots: 0, + max_item_slots: 3 + } +]; diff --git a/data/users.js b/data/users.js index a0914e4..93cdfb7 100644 --- a/data/users.js +++ b/data/users.js @@ -1,6 +1,6 @@ module.exports = [ { - email: 'john@arbuckle.com', - hash: 1234 + email: 'testemail@gmail.com', + hash: 1234, } ]; diff --git a/lib/app.js b/lib/app.js index 1687831..d947a8c 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1,18 +1,116 @@ +// I'm grading off the dev branch here. Is that right? Is dev the most updated code? The master branch didn't seem like it const express = require('express'); const cors = require('cors'); const client = require('./client.js'); const app = express(); +const request = require('superagent'); app.use(cors()); app.use(express.json()); app.use(express.urlencoded({ extended: false })); +const ensureAuth = require('./auth/ensure-auth'); +const createAuthRoutes = require('./auth/create-auth-routes'); -app.get('/animals', async(req, res) => { - const data = await client.query('SELECT * from animals'); +const authRoutes = createAuthRoutes({ + selectUser(email) { + return client.query(` + SELECT id, email, hash + FROM users + WHERE email = $1; + `, + [email] + ).then(result => result.rows[0]); + }, + insertUser(user, hash) { + return client.query(` + INSERT into users (email, hash) + VALUES ($1, $2) + RETURNING id, email; + `, + [user.email, hash] + ).then(result => result.rows[0]); + } +}); + +app.use('/auth', authRoutes); +app.use('/api', ensureAuth); + +app.get('/color', async(req, res) => { + // nice work getting this endpoint together so quickly! + const data = await request.get('http://thecolorapi.com/scheme?hex=0047AB&rgb=0,71,171&hsl=215,100%,34%&cmyk=100,58,0,33&format=json&mode=analogic&count=6'); + + res.json(data.body); +}); +app.get('/locations', async(req, res) => { + const data = await client.query('SELECT * from locations'); + + res.json(data.rows); +}); + +app.get('/events/:eventId', async(req, res) => { + const data = await client.query(` + select * from events where events.planet_id = $1 + `, [req.params.eventId]); + + res.json(data.rows); +}); + +app.get('/shipchoices', async(req, res) => { + const data = await client.query('SELECT * from shipchoices'); + + res.json(data.rows); +}); + +app.get('/usership/:id', async(req, res) => { + const data = await client.query(` + SELECT shipchoices.id, shipchoices.ship_name, shipchoices.ship_fuel, shipchoices.ship_hull, shipchoices.base_combat, shipchoices.base_diplomacy, shipchoices.base_science, shipchoices.used_item_slots, shipchoices.max_item_slots + FROM shipchoices + WHERE shipchoices.id = $1 +`, [req.params.id]); res.json(data.rows); }); +app.get('/randomPlanet', async(req, res) => { + const data = await client.query(` + SELECT locations.id, locations.location_name, locations.location_type, locations.location_image, locations.location_description, events + FROM locations + JOIN events + on locations.event_id = events.planet_id +`,); + + res.json(data.rows); +}); + + +app.post('/api/loggedinuser', async(req, res) => { + const data = await client.query(` + INSERT INTO loggedinuser (name, score, owner_id) + values ($1, $2, $3) + returning * + `, [req.body.name, req.body.score, req.userId]); + res.json(data.rows); +}); + +app.get('/api/loggedinuser', async(req, res) => { + const data = await client.query(` + SELECT * FROM loggedinuser + WHERE owner_id = $1 + `, [req.userId]); + res.json(data.rows); +}); + +// seems like you could have managed this stuff with req.userId +app.put('/api/loggedinuser', async(req, res) => { + const data = await client.query(` + UPDATE loggedinuser + SET score = score + 1 + WHERE owner_id=$1 + `, [req.userId]); + res.json(data.rows); +}); + + app.use(require('./middleware/error')); module.exports = app; diff --git a/lib/auth/create-auth-routes.js b/lib/auth/create-auth-routes.js index b41ac0c..c0747ea 100644 --- a/lib/auth/create-auth-routes.js +++ b/lib/auth/create-auth-routes.js @@ -1,7 +1,7 @@ const express = require('express'); const bcrypt = require('bcryptjs'); const jwt = require('./jwt'); -const client = require('../client').connect(); +const client = require('../client'); const ensureAuth = require('./ensure-auth'); function getProfileWithToken(user) { diff --git a/server.js b/server.js index 564a9ca..7fb15fa 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,5 @@ +// Did you end up running postman tests and screenshots of your passing tests? + require('dotenv').config(); require('./lib/client').connect();