36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
// 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
|
|
}; |