diff --git a/client/styles/index.scss b/client/styles/index.scss index 95d5172..bdbf7db 100644 --- a/client/styles/index.scss +++ b/client/styles/index.scss @@ -37,8 +37,6 @@ body { h1 { color: $foreground; font-family: 'Lato Bold'; - text-shadow: -1px 0 rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.3), - 1px 0 rgba(255, 255, 255, 0.3), 0 -1px rgba(255, 255, 255, 0.3); } #lazy{ diff --git a/server/graphQLServer/schema.js b/server/graphQLServer/schema.js index 2aa5fba..fe301cd 100644 --- a/server/graphQLServer/schema.js +++ b/server/graphQLServer/schema.js @@ -1,6 +1,6 @@ const { makeExecutableSchema } = require('graphql-tools'); const { Pool } = require('pg'); -const PG_URI = 'postgres://rviqlbrx:EAr3zdbJKfuruitHjFLKg5EItc_1wMfK@ziggy.db.elephantsql.com:5432/rviqlbrx'; +const PG_URI = 'postgres://sugmjzbp:wvcZ6SvHu61w8qdmDYBb1uvdnqtLZ_82@suleiman.db.elephantsql.com:5432/sugmjzbp'; const pool = new Pool({ connectionString: PG_URI @@ -15,142 +15,259 @@ db.query = (text,params, callback) => { const typeDefs = ` type Query { - books: [Book!]! - book(id: Int!): Book! - authors: [Author!]! - author(id: Int!): Author! - product: [Product!]! - productByID(product_id: Int!): Product! - bill: [Bill!]! - billByID(bill_id: Int!): Bill! - person: [Person!]! - personByID(id: Int!): Person! - orders: [Order!]! - order(id: Int!): Order! + people: [Person!]! + person(_id: Int!): Person! + films: [Film!]! + film(_id: Int!): Film! + planets: [Planet!]! + planet(_id: Int!): Planet! + species: [Species!]! + speciesByID(_id: Int!): Species! + vessels: [Vessel!]! + vessel(_id: Int!): Vessel! + starshipSpecs: [StarshipSpec!]! + starshipSpec(_id: Int!): StarshipSpec! } type Mutation { - createBook( - title: String!, - primary_author: String, - author_id: Int, - ): Book! - - updateBook( - title: String!, - primary_author: String, - id: Int!, - author_id: Int, - ): Book! - - deleteBook(id: ID!): Book! - - createAuthor( - name: String!, - book_id: Int, - ): Author! - - updateAuthor( - name: String!, - book_id: Int, - id: Int!, - ): Author! - - deleteAuthor(id: ID!): Author! - - createProduct( - product: String!, - price: Int!, - ): Product! - - updateProduct( - product: String!, - product_id: Int!, - price: Int!, - ): Product! - - deleteProduct(product_id: ID!): Product! - - createBill( - bill: String!, - billdate: String!, - ): Bill! - - updateBill( - bill: String!, - bill_id: Int!, - billdate: String!, - ): Bill! - - deleteBill(bill_id: ID!): Bill! - createPerson( - email: String!, - order_id: Int, + gender: String, + species_id: Int, + homeworld_id: Int, + height: Int, + mass: String, + hair_color: String, + skin_color: String, + eye_color: String, name: String!, + birth_year: String, ): Person! updatePerson( - email: String!, - id: Int!, - order_id: Int, + gender: String, + species_id: Int, + homeworld_id: Int, + height: Int, + _id: Int!, + mass: String, + hair_color: String, + skin_color: String, + eye_color: String, name: String!, + birth_year: String, ): Person! - deletePerson(id: ID!): Person! - - createOrder( - items: String!, - ): Order! - - updateOrder( - items: String!, - id: Int!, - ): Order! + deletePerson(_id: ID!): Person! - deleteOrder(id: ID!): Order! + createFilm( + director: String!, + opening_crawl: String!, + episode_id: Int!, + title: String!, + release_date: String!, + producer: String!, + ): Film! + + updateFilm( + director: String!, + opening_crawl: String!, + episode_id: Int!, + _id: Int!, + title: String!, + release_date: String!, + producer: String!, + ): Film! + + deleteFilm(_id: ID!): Film! + + createPlanet( + orbital_period: Int, + climate: String, + gravity: String, + terrain: String, + surface_water: String, + population: Int, + name: String, + rotation_period: Int, + diameter: Int, + ): Planet! + + updatePlanet( + orbital_period: Int, + climate: String, + gravity: String, + terrain: String, + surface_water: String, + population: Int, + _id: Int!, + name: String, + rotation_period: Int, + diameter: Int, + ): Planet! + + deletePlanet(_id: ID!): Planet! + + createSpecies( + hair_colors: String, + name: String!, + classification: String, + average_height: String, + average_lifespan: String, + skin_colors: String, + eye_colors: String, + language: String, + homeworld_id: Int, + ): Species! + + updateSpecies( + hair_colors: String, + name: String!, + classification: String, + average_height: String, + average_lifespan: String, + skin_colors: String, + eye_colors: String, + language: String, + homeworld_id: Int, + _id: Int!, + ): Species! + + deleteSpecies(_id: ID!): Species! + + createVessel( + cost_in_credits: Int, + length: String, + vessel_type: String!, + model: String, + manufacturer: String, + name: String!, + vessel_class: String!, + max_atmosphering_speed: String, + crew: Int, + passengers: Int, + cargo_capacity: String, + consumables: String, + ): Vessel! + + updateVessel( + cost_in_credits: Int, + length: String, + vessel_type: String!, + model: String, + manufacturer: String, + name: String!, + vessel_class: String!, + max_atmosphering_speed: String, + crew: Int, + passengers: Int, + cargo_capacity: String, + consumables: String, + _id: Int!, + ): Vessel! + + deleteVessel(_id: ID!): Vessel! + + createStarshipSpec( + vessel_id: Int!, + MGLT: String, + hyperdrive_rating: String, + ): StarshipSpec! + + updateStarshipSpec( + _id: Int!, + vessel_id: Int!, + MGLT: String, + hyperdrive_rating: String, + ): StarshipSpec! + + deleteStarshipSpec(_id: ID!): StarshipSpec! } - type Book { - id: Int! - title: String! - primary_author: String - author: Author - authors: [Author] + type Person { + _id: Int! + gender: String + height: Int + mass: String + hair_color: String + skin_color: String + eye_color: String + name: String! + birth_year: String + films: [Film] + vessels: [Vessel] + species: [Species] + planets: [Planet] } - type Author { - id: Int! - name: String! - book: Book - books: [Book] + type Film { + _id: Int! + director: String! + opening_crawl: String! + episode_id: Int! + title: String! + release_date: String! + producer: String! + planets: [Planet] + people: [Person] + vessels: [Vessel] + species: [Species] } - type Product { - product_id: Int! - product: String! - price: Int - bill: [Bill] + type Planet { + _id: Int! + orbital_period: Int + climate: String + gravity: String + terrain: String + surface_water: String + population: Int + name: String + rotation_period: Int + diameter: Int + films: [Film] + species: [Species] + people: [Person] } - type Bill { - bill_id: Int! - bill: String! - billdate: String - product: [Product] + type Species { + _id: Int! + hair_colors: String + name: String! + classification: String + average_height: String + average_lifespan: String + skin_colors: String + eye_colors: String + language: String + people: [Person] + films: [Film] + planets: [Planet] } - type Person { - id: Int! - email: String! + type Vessel { + _id: Int! + cost_in_credits: Int + length: String + vessel_type: String! + model: String + manufacturer: String name: String! - orders: [Order] + vessel_class: String! + max_atmosphering_speed: String + crew: Int + passengers: Int + cargo_capacity: String + consumables: String + films: [Film] + people: [Person] + starshipSpecs: [StarshipSpec] } - type Order { - id: Int! - items: String! - person: [Person] + type StarshipSpec { + _id: Int! + MGLT: String + hyperdrive_rating: String + vessels: [Vessel] } `; @@ -160,91 +277,91 @@ const typeDefs = ` const resolvers = { Query: { - book: (parent, args) => { - const query = 'SELECT * FROM books WHERE id = $1'; - const values = [args.id]; + person: (parent, args) => { + const query = 'SELECT * FROM people WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - books: () => { - const query = 'SELECT * FROM books'; + people: () => { + const query = 'SELECT * FROM people'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); }, - author: (parent, args) => { - const query = 'SELECT * FROM authors WHERE id = $1'; - const values = [args.id]; + film: (parent, args) => { + const query = 'SELECT * FROM films WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - authors: () => { - const query = 'SELECT * FROM authors'; + films: () => { + const query = 'SELECT * FROM films'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); }, - productByID: (parent, args) => { - const query = 'SELECT * FROM product WHERE product_id = $1'; - const values = [args.product_id]; + planet: (parent, args) => { + const query = 'SELECT * FROM planets WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - product: () => { - const query = 'SELECT * FROM product'; + planets: () => { + const query = 'SELECT * FROM planets'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); }, - billByID: (parent, args) => { - const query = 'SELECT * FROM bill WHERE bill_id = $1'; - const values = [args.bill_id]; + speciesByID: (parent, args) => { + const query = 'SELECT * FROM species WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - bill: () => { - const query = 'SELECT * FROM bill'; + species: () => { + const query = 'SELECT * FROM species'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); }, - personByID: (parent, args) => { - const query = 'SELECT * FROM person WHERE id = $1'; - const values = [args.id]; + vessel: (parent, args) => { + const query = 'SELECT * FROM vessels WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - person: () => { - const query = 'SELECT * FROM person'; + vessels: () => { + const query = 'SELECT * FROM vessels'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); }, - order: (parent, args) => { - const query = 'SELECT * FROM orders WHERE id = $1'; - const values = [args.id]; + starshipSpec: (parent, args) => { + const query = 'SELECT * FROM starship_specs WHERE _id = $1'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - orders: () => { - const query = 'SELECT * FROM orders'; + starshipSpecs: () => { + const query = 'SELECT * FROM starship_specs'; return db.query(query) .then(data => data.rows) .catch(err => new Error(err)); @@ -253,145 +370,145 @@ const typeDefs = ` Mutation: { - createBook: (parent, args) => { - const query = 'INSERT INTO books(title, primary_author, author_id) VALUES($1, $2, $3) RETURNING *'; - const values = [args.title, args.primary_author, args.author_id]; + createPerson: (parent, args) => { + const query = 'INSERT INTO people(gender, species_id, homeworld_id, height, mass, hair_color, skin_color, eye_color, name, birth_year) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *'; + const values = [args.gender, args.species_id, args.homeworld_id, args.height, args.mass, args.hair_color, args.skin_color, args.eye_color, args.name, args.birth_year]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updateBook: (parent, args) => { - const query = 'UPDATE books SET title=$1, primary_author=$2, author_id=$3 WHERE id = $4 RETURNING *'; - const values = [args.title, args.primary_author, args.author_id, args.id]; + updatePerson: (parent, args) => { + const query = 'UPDATE people SET gender=$1, species_id=$2, homeworld_id=$3, height=$4, mass=$5, hair_color=$6, skin_color=$7, eye_color=$8, name=$9, birth_year=$10 WHERE _id = $11 RETURNING *'; + const values = [args.gender, args.species_id, args.homeworld_id, args.height, args.mass, args.hair_color, args.skin_color, args.eye_color, args.name, args.birth_year, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deleteBook: (parent, args) => { - const query = 'DELETE FROM books WHERE id = $1 RETURNING *'; - const values = [args.id]; + deletePerson: (parent, args) => { + const query = 'DELETE FROM people WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - createAuthor: (parent, args) => { - const query = 'INSERT INTO authors(name, book_id) VALUES($1, $2) RETURNING *'; - const values = [args.name, args.book_id]; + createFilm: (parent, args) => { + const query = 'INSERT INTO films(director, opening_crawl, episode_id, title, release_date, producer) VALUES($1, $2, $3, $4, $5, $6) RETURNING *'; + const values = [args.director, args.opening_crawl, args.episode_id, args.title, args.release_date, args.producer]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updateAuthor: (parent, args) => { - const query = 'UPDATE authors SET name=$1, book_id=$2 WHERE id = $3 RETURNING *'; - const values = [args.name, args.book_id, args.id]; + updateFilm: (parent, args) => { + const query = 'UPDATE films SET director=$1, opening_crawl=$2, episode_id=$3, title=$4, release_date=$5, producer=$6 WHERE _id = $7 RETURNING *'; + const values = [args.director, args.opening_crawl, args.episode_id, args.title, args.release_date, args.producer, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deleteAuthor: (parent, args) => { - const query = 'DELETE FROM authors WHERE id = $1 RETURNING *'; - const values = [args.id]; + deleteFilm: (parent, args) => { + const query = 'DELETE FROM films WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - createProduct: (parent, args) => { - const query = 'INSERT INTO product(product, price) VALUES($1, $2) RETURNING *'; - const values = [args.product, args.price]; + createPlanet: (parent, args) => { + const query = 'INSERT INTO planets(orbital_period, climate, gravity, terrain, surface_water, population, name, rotation_period, diameter) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *'; + const values = [args.orbital_period, args.climate, args.gravity, args.terrain, args.surface_water, args.population, args.name, args.rotation_period, args.diameter]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updateProduct: (parent, args) => { - const query = 'UPDATE product SET product=$1, price=$2 WHERE product_id = $3 RETURNING *'; - const values = [args.product, args.price, args.product_id]; + updatePlanet: (parent, args) => { + const query = 'UPDATE planets SET orbital_period=$1, climate=$2, gravity=$3, terrain=$4, surface_water=$5, population=$6, name=$7, rotation_period=$8, diameter=$9 WHERE _id = $10 RETURNING *'; + const values = [args.orbital_period, args.climate, args.gravity, args.terrain, args.surface_water, args.population, args.name, args.rotation_period, args.diameter, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deleteProduct: (parent, args) => { - const query = 'DELETE FROM product WHERE product_id = $1 RETURNING *'; - const values = [args.product_id]; + deletePlanet: (parent, args) => { + const query = 'DELETE FROM planets WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - createBill: (parent, args) => { - const query = 'INSERT INTO bill(bill, billdate) VALUES($1, $2) RETURNING *'; - const values = [args.bill, args.billdate]; + createSpecies: (parent, args) => { + const query = 'INSERT INTO species(hair_colors, name, classification, average_height, average_lifespan, skin_colors, eye_colors, language, homeworld_id) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *'; + const values = [args.hair_colors, args.name, args.classification, args.average_height, args.average_lifespan, args.skin_colors, args.eye_colors, args.language, args.homeworld_id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updateBill: (parent, args) => { - const query = 'UPDATE bill SET bill=$1, billdate=$2 WHERE bill_id = $3 RETURNING *'; - const values = [args.bill, args.billdate, args.bill_id]; + updateSpecies: (parent, args) => { + const query = 'UPDATE species SET hair_colors=$1, name=$2, classification=$3, average_height=$4, average_lifespan=$5, skin_colors=$6, eye_colors=$7, language=$8, homeworld_id=$9 WHERE _id = $10 RETURNING *'; + const values = [args.hair_colors, args.name, args.classification, args.average_height, args.average_lifespan, args.skin_colors, args.eye_colors, args.language, args.homeworld_id, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deleteBill: (parent, args) => { - const query = 'DELETE FROM bill WHERE bill_id = $1 RETURNING *'; - const values = [args.bill_id]; + deleteSpecies: (parent, args) => { + const query = 'DELETE FROM species WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - createPerson: (parent, args) => { - const query = 'INSERT INTO person(email, order_id, name) VALUES($1, $2, $3) RETURNING *'; - const values = [args.email, args.order_id, args.name]; + createVessel: (parent, args) => { + const query = 'INSERT INTO vessels(cost_in_credits, length, vessel_type, model, manufacturer, name, vessel_class, max_atmosphering_speed, crew, passengers, cargo_capacity, consumables) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *'; + const values = [args.cost_in_credits, args.length, args.vessel_type, args.model, args.manufacturer, args.name, args.vessel_class, args.max_atmosphering_speed, args.crew, args.passengers, args.cargo_capacity, args.consumables]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updatePerson: (parent, args) => { - const query = 'UPDATE person SET email=$1, order_id=$2, name=$3 WHERE id = $4 RETURNING *'; - const values = [args.email, args.order_id, args.name, args.id]; + updateVessel: (parent, args) => { + const query = 'UPDATE vessels SET cost_in_credits=$1, length=$2, vessel_type=$3, model=$4, manufacturer=$5, name=$6, vessel_class=$7, max_atmosphering_speed=$8, crew=$9, passengers=$10, cargo_capacity=$11, consumables=$12 WHERE _id = $13 RETURNING *'; + const values = [args.cost_in_credits, args.length, args.vessel_type, args.model, args.manufacturer, args.name, args.vessel_class, args.max_atmosphering_speed, args.crew, args.passengers, args.cargo_capacity, args.consumables, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deletePerson: (parent, args) => { - const query = 'DELETE FROM person WHERE id = $1 RETURNING *'; - const values = [args.id]; + deleteVessel: (parent, args) => { + const query = 'DELETE FROM vessels WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - createOrder: (parent, args) => { - const query = 'INSERT INTO orders(items) VALUES($1) RETURNING *'; - const values = [args.items]; + createStarshipSpec: (parent, args) => { + const query = 'INSERT INTO starship_specs(vessel_id, MGLT, hyperdrive_rating) VALUES($1, $2, $3) RETURNING *'; + const values = [args.vessel_id, args.MGLT, args.hyperdrive_rating]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - updateOrder: (parent, args) => { - const query = 'UPDATE orders SET items=$1 WHERE id = $2 RETURNING *'; - const values = [args.items, args.id]; + updateStarshipSpec: (parent, args) => { + const query = 'UPDATE starship_specs SET vessel_id=$1, MGLT=$2, hyperdrive_rating=$3 WHERE _id = $4 RETURNING *'; + const values = [args.vessel_id, args.MGLT, args.hyperdrive_rating, args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); }, - deleteOrder: (parent, args) => { - const query = 'DELETE FROM orders WHERE id = $1 RETURNING *'; - const values = [args.id]; + deleteStarshipSpec: (parent, args) => { + const query = 'DELETE FROM starship_specs WHERE _id = $1 RETURNING *'; + const values = [args._id]; return db.query(query, values) .then(data => data.rows[0]) .catch(err => new Error(err)); @@ -399,55 +516,139 @@ const typeDefs = ` }, - Book: { + Person: { - authors: (books) => { - const query = 'SELECT * FROM authors WHERE book_id = $1'; - const values = [books.id]; + films: (people) => { + const query = 'SELECT * FROM films LEFT OUTER JOIN people_in_films ON films._id = people_in_films.film_id WHERE people_in_films.person_id = $1'; + const values = [people._id]; return db.query(query, values) - .then(data => data.rows[0]) + .then(data => data.rows) .catch(err => new Error(err)); - }, + }, + species: (people) => { + const query = 'SELECT species.* FROM species LEFT OUTER JOIN people ON species._id = people._id WHERE people._id = $1'; + const values = [people._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + planets: (people) => { + const query = 'SELECT planets.* FROM planets LEFT OUTER JOIN people ON planets._id = people._id WHERE people._id = $1'; + const values = [people._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + vessels: (people) => { + const query = 'SELECT * FROM vessels LEFT OUTER JOIN pilots ON vessels._id = pilots.vessel_id WHERE pilots.person_id = $1'; + const values = [people._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, }, - Author: { + Film: { - books: (authors) => { - const query = 'SELECT * FROM books WHERE author_id = $1'; - const values = [authors.id]; + planets: (films) => { + const query = 'SELECT * FROM planets LEFT OUTER JOIN planets_in_films ON planets._id = planets_in_films.planet_id WHERE planets_in_films.film_id = $1'; + const values = [films._id]; return db.query(query, values) - .then(data => data.rows[0]) + .then(data => data.rows) .catch(err => new Error(err)); - }, + }, + people: (films) => { + const query = 'SELECT * FROM people LEFT OUTER JOIN people_in_films ON people._id = people_in_films.person_id WHERE people_in_films.film_id = $1'; + const values = [films._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + vessels: (films) => { + const query = 'SELECT * FROM vessels LEFT OUTER JOIN vessels_in_films ON vessels._id = vessels_in_films.vessel_id WHERE vessels_in_films.film_id = $1'; + const values = [films._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + species: (films) => { + const query = 'SELECT * FROM species LEFT OUTER JOIN species_in_films ON species._id = species_in_films.species_id WHERE species_in_films.film_id = $1'; + const values = [films._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, }, - Product: { + Planet: { - bill: (product) => { - const query = 'SELECT * FROM bill LEFT OUTER JOIN bill_product ON bill.bill_id = bill_product.bill_id WHERE bill_product.product_id = $1'; - const values = [product.product_id]; + films: (planets) => { + const query = 'SELECT * FROM films LEFT OUTER JOIN planets_in_films ON films._id = planets_in_films.film_id WHERE planets_in_films.planet_id = $1'; + const values = [planets._id]; return db.query(query, values) .then(data => data.rows) .catch(err => new Error(err)); }, + species: (planets) => { + const query = 'SELECT * FROM species WHERE homeworld_id $1'; + const values = [planets._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + people: (planets) => { + const query = 'SELECT * FROM people WHERE homeworld_id $1'; + const values = [planets._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, }, - Bill: { + Species: { - product: (bill) => { - const query = 'SELECT * FROM product LEFT OUTER JOIN bill_product ON product.product_id = bill_product.product_id WHERE bill_product.bill_id = $1'; - const values = [bill.bill_id]; + people: (species) => { + const query = 'SELECT * FROM people WHERE species_id $1'; + const values = [species._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + films: (species) => { + const query = 'SELECT * FROM films LEFT OUTER JOIN species_in_films ON films._id = species_in_films.film_id WHERE species_in_films.species_id = $1'; + const values = [species._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + planets: (species) => { + const query = 'SELECT planets.* FROM planets LEFT OUTER JOIN species ON planets._id = species._id WHERE species._id = $1'; + const values = [species._id]; return db.query(query, values) .then(data => data.rows) .catch(err => new Error(err)); }, }, - Order: { + Vessel: { - person: (orders) => { - const query = 'SELECT * FROM person WHERE order_id $1'; - const values = [orders.id]; + films: (vessels) => { + const query = 'SELECT * FROM films LEFT OUTER JOIN vessels_in_films ON films._id = vessels_in_films.film_id WHERE vessels_in_films.vessel_id = $1'; + const values = [vessels._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + people: (vessels) => { + const query = 'SELECT * FROM people LEFT OUTER JOIN pilots ON people._id = pilots.person_id WHERE pilots.vessel_id = $1'; + const values = [vessels._id]; + return db.query(query, values) + .then(data => data.rows) + .catch(err => new Error(err)); + }, + starshipSpecs: (vessels) => { + const query = 'SELECT * FROM starship_specs WHERE vessel_id $1'; + const values = [vessels._id]; return db.query(query, values) .then(data => data.rows) .catch(err => new Error(err));