fix funzionante

This commit is contained in:
xfarrow 2023-10-12 16:47:41 +02:00
parent d9bbc622c4
commit 70f3b1f754

View File

@ -3,7 +3,7 @@ const crypto = require('crypto');
const pgp = require('pg-promise')(); const pgp = require('pg-promise')();
const Pool = require('pg-pool'); const Pool = require('pg-pool');
const dbConfig = { const database_configuration = {
host: "localhost", host: "localhost",
port: 5432, port: 5432,
database: "Blink", database: "Blink",
@ -11,10 +11,7 @@ const dbConfig = {
password: "postgres" password: "postgres"
}; };
// Create a new connection pool const db = pgp(database_configuration);
const db = pgp({
pool: new Pool(dbConfig),
});
function register(req, res){ function register(req, res){
const userData = req.body; const userData = req.body;
@ -76,7 +73,7 @@ function register(req, res){
} }
async function register_async(req, res){ async function register_async(req, res){
console.log(process.env.DB_PASSWORD);
const userData = req.body; const userData = req.body;
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
@ -89,7 +86,8 @@ async function register_async(req, res){
const hashPasswordPromise = bcrypt.hash(userData.password, 10); const hashPasswordPromise = bcrypt.hash(userData.password, 10);
try{ try{
const result = await db.tx(async (t) => { // Begin transaction
await db.tx(async (t) => {
// Inserting in "Person" table // Inserting in "Person" table
const userInsertQuery = ` const userInsertQuery = `
@ -108,7 +106,7 @@ async function register_async(req, res){
]); ]);
const activationLinkInsertQuery = ` const activationLinkInsertQuery = `
INSERT INTO "ActivationLink" (user_id, activation_code) INSERT INTO "ActivationLink" (person_id, identifier)
VALUES ($1, $2) VALUES ($1, $2)
RETURNING *`; RETURNING *`;
@ -116,7 +114,7 @@ async function register_async(req, res){
userResult.id, userResult.id,
activationLink, activationLink,
]); ]);
return res.status(200).json({ user: userResult, activationLink: activationLinkResult }); return res.status(200).json({ activationLink: activationLinkResult.identifier });
}); });
} }
catch (error){ catch (error){