-
Notifications
You must be signed in to change notification settings - Fork 0
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
26eeb1b
commit dae6d25
Showing
16 changed files
with
299 additions
and
107 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
This file was deleted.
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,36 @@ | ||
// Items in the global namespace are accessible throught out the node application | ||
// https://node-postgres.com/features/pooling | ||
const Pool = require("pg").Pool; | ||
// https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs | ||
const pool = new Pool({ | ||
user: process.env.POSTGRES_USER, | ||
host: process.env.POSTGRES_HOST, | ||
database: process.env.POSTGRES_DB, | ||
password: process.env.POSTGRES_PASSWORD, | ||
port: process.env.POSTGRES_PORT, | ||
}); | ||
|
||
//get all from our database | ||
const getData = async (sql_query, values) => { | ||
try { | ||
return await new Promise(function (resolve, reject) { | ||
pool.query(sql_query, values, (error, results) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
if (results && results.rows) { | ||
resolve(results.rows); | ||
} else { | ||
reject(new Error("No results found")); | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
|
||
module.exports = { | ||
getData, | ||
}; |
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
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
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,34 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const getData = require("../db").getData; | ||
|
||
/** | ||
* @desc Lister toutes les réalisations recensées | ||
*/ | ||
router.get("/realisations", (req, res, next) => { | ||
// Define the query | ||
SQLquery = "SELECT * FROM realisations ORDER BY r_début DESC;" | ||
getData(SQLquery) | ||
.then((data) => { | ||
res.render('realisations.ejs', | ||
{ realisations: data, title: req.app.locals.title }); | ||
}); | ||
}); | ||
|
||
/** | ||
* @desc Voir le détail d'une réalisation | ||
*/ | ||
router.get("/realisation/:id", (req, res, next) => { | ||
var id = req.params.id; | ||
// Define the query | ||
SQLquery = `SELECT * FROM realisations WHERE id = $1::int;` | ||
getData(SQLquery, [id]) | ||
.then((data) => { | ||
console.log(data[0]) | ||
res.render('realisation_view.ejs', | ||
{ realisation: data[0], title: req.app.locals.title }); | ||
}); | ||
}); | ||
|
||
// Export the router object so index.js can access it | ||
module.exports = router; |
Oops, something went wrong.