This commit is contained in:
Joaquín Torres 2020-03-15 00:29:43 -03:00
parent 711f4dfdc6
commit b55d99ccfd
2 changed files with 37 additions and 2 deletions

1
.gitignore vendored
View File

@ -111,4 +111,3 @@ credentials.json
.idea
package-lock.json
database.js

36
database.js Normal file
View File

@ -0,0 +1,36 @@
// Postgres
const Pool = require('pg').Pool;
// Postgres config.
let postgresConfig = require("./credentials.json").postgres;
// Postgres initialization
const pool = new Pool(postgresConfig);
async function createUser(userId, userName) {
await pool.query('INSERT INTO users (user_id, user_name) VALUES ($1, $2)', [userId, userName]);
let res = await pool.query('SELECT * FROM users WHERE user_id = $1', [userId]);
return res.rows;
}
async function getUser(userId) {
let res = await pool.query('SELECT * FROM users WHERE user_id = $1', [userId]);
return res.rows;
}
async function userFinishedTheirThesis(userId, date, rt_date) {
let res = await pool.query('UPDATE USERS SET FT_DATE = $1, RT_DATE = $2 WHERE USER_ID = $3', [date, rt_date, userId]);
return res.rows;
}
async function reviewDateUpdate(userId, date) {
let res = await pool.query('UPDATE USERS SET RT_DATE = $1 WHERE USER_ID = $2', [date, userId]);
return res.rows;
}
module.exports = {
createUser,
getUser,
userFinishedTheirThesis,
reviewDateUpdate
};