-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95cda94
commit 8560f46
Showing
9 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const db = require('../models/stackModels'); | ||
|
||
const stackController = {}; | ||
|
||
|
||
// stackController.getStack = (req, res, next) => { | ||
|
||
// } | ||
// starWarsController.getCharacters = (req, res, next) => { | ||
// // write code here | ||
// // decalre variable that contains SQL query string | ||
// // pass it into db query | ||
// // write and send a query to grab all the columns from the people table. | ||
// const people = 'SELECT p.*, s.name AS species, pl.name AS homeworld FROM people AS p JOIN species AS s ON p.species_id = s._id JOIN planets AS pl ON pl._id = p.homeworld_id'; | ||
|
||
// db.query(people) | ||
// .then(resolve => { | ||
// res.locals = resolve.rows; | ||
// next(); | ||
// }) | ||
// .catch((err) => { | ||
// next(err); | ||
// }); | ||
// } | ||
|
||
// starWarsController.getSpecies = (req, res, next) => { | ||
// // write code here | ||
// const species_id = req.query.id; | ||
// const species = `SELECT species._id, species.classification, species.average_height, species.average_lifespan, species.language, planets.name AS homeworld | ||
// FROM species | ||
// LEFT OUTER JOIN planets | ||
// ON planets._id = species.homeworld_id | ||
// WHERE species._id =${species_id}`; | ||
// db.query(species) | ||
// .then(resolve => { | ||
// res.locals = resolve.rows[0]; | ||
// next(); | ||
// }) | ||
// .catch((err) => { | ||
// next(err); | ||
// }); | ||
// } | ||
|
||
// starWarsController.getHomeworld = (req, res, next) => { | ||
// // write code here | ||
// const homeworld_id = req.query.id; | ||
// const homeworld = `SELECT _id, rotation_period, orbital_period, diameter, climate, gravity, terrain, surface_water, population | ||
// FROM planets | ||
// WHERE _id = ${homeworld_id}`; | ||
// db.query(homeworld) | ||
// .then(resolve => { | ||
// res.locals = resolve.rows[0]; | ||
// next(); | ||
// }) | ||
// .catch((err) => { | ||
// next(err); | ||
// }); | ||
// } | ||
|
||
// starWarsController.getFilm = (req, res, next) => { | ||
// // write code here | ||
|
||
// next(); | ||
// } | ||
|
||
// starWarsController.addCharacter = (req, res, next) => { | ||
// // write code here | ||
// console.log(req); | ||
// const characterObj = req.body; | ||
// const character = `INSERT INTO people (name, gender, species_id, birth_year, eye_color, skin_color, hair_color, mass, height, homeworld_id) | ||
// VALUES ('${characterObj.name}', '${characterObj.gender}', '${characterObj.species_id}', '${characterObj.birth_year}', '${characterObj.eye_color}', '${characterObj.skin_color}', '${characterObj.hair_color}', '${characterObj.mass}', '${characterObj.height}', '${characterObj.homeworld_id}')`; | ||
// db.query(character) | ||
// .then(resolve => { | ||
// console.log('this should be inserted'); | ||
// res.status(200); | ||
// next(); | ||
// }) | ||
// .catch((err) => { | ||
// next(err); | ||
// }); | ||
//} | ||
|
||
module.exports = stackController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { Pool } = require('pg'); | ||
|
||
const PG_URI = 'postgres://fqimhpba:[email protected]:5432/fqimhpba'; | ||
|
||
// create a new pool here using the connection string above | ||
const pool = new Pool({ | ||
connectionString: PG_URI | ||
}); | ||
|
||
// We export an object that contains a property called query, | ||
// which is a function that returns the invocation of pool.query() after logging the query | ||
// This will be required in the controllers to be the access point to the database | ||
module.exports = { | ||
query: (text, params, callback) => { | ||
console.log('executed query', text); | ||
return pool.query(text, params, callback); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const express = require('express'); | ||
const modelsController = require('../controllers/stackControllers'); | ||
const router = express.Router(); | ||
|
||
|
||
router.get('/', (req, res) => { | ||
res.send('Success!'); | ||
}); | ||
|
||
module.exports = router; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
"exclude": [ | ||
"node_modules" | ||
] | ||
} | ||
} |