-
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.
Merge branch 'master' of https://github.com/Star-Nosed-Mole/Bubble-Stack
- Loading branch information
Showing
11 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
.vscode | ||
.env |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,41 @@ | ||
const db = require('../models/stackModels'); | ||
const { stack } = require('../routes/api'); | ||
|
||
const stackController = {}; | ||
|
||
|
||
stackController.getAll = (req, res, next) => { | ||
|
||
const queryAll = `SELECT libraries.name, types.name AS type, framework.name AS framework FROM libraries | ||
INNER JOIN types ON libraries.type_id = types.type_id | ||
INNER JOIN framework ON libraries.framework_id = framework.framework_id;`; | ||
|
||
db.query(queryAll) | ||
.then(data=> { | ||
res.locals.all = data.rows; | ||
return next(); | ||
}) | ||
.catch((err) => { | ||
return next(err); | ||
}); | ||
} | ||
|
||
|
||
stackController.findOne = (req, res, next) => { | ||
const name = req.body.name; | ||
const queryOne = `SELECT libraries.name, types.name AS type, framework.name AS framework FROM libraries | ||
INNER JOIN types ON libraries.type_id = types.type_id | ||
INNER JOIN framework ON libraries.framework_id = framework.framework_id | ||
WHERE libraries.name = '${name}'; `; | ||
db.query(queryOne) | ||
.then(data=> { | ||
console.log(data.rows); | ||
res.locals.one = data.rows[0]; | ||
return next(); | ||
}) | ||
.catch((err) => { | ||
return 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,19 @@ | ||
// import PG_URI from '../../.env'; | ||
const { Pool } = require('pg'); | ||
|
||
require("dotenv").config(); | ||
|
||
// create a new pool here using the connection string above | ||
const pool = new Pool({ | ||
connectionString: process.env.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,19 @@ | ||
const express = require('express'); | ||
const modelsController = require('../controllers/stackControllers'); | ||
const router = express.Router(); | ||
|
||
|
||
router.get('/', | ||
modelsController.getAll, | ||
(req, res) => { | ||
res.status(200).json(res.locals.all); | ||
}); | ||
|
||
router.post('/one', | ||
modelsController.findOne, | ||
(req, res) => { | ||
res.status(200).json(res.locals.one); | ||
}); | ||
|
||
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" | ||
] | ||
} | ||
} |