From 70f3b1f75473badbdade7fdab12bea62731c2a17 Mon Sep 17 00:00:00 2001 From: xfarrow Date: Thu, 12 Oct 2023 16:47:41 +0200 Subject: [PATCH] fix funzionante --- backend/apis/nodejs/api_controller.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/apis/nodejs/api_controller.js b/backend/apis/nodejs/api_controller.js index 303f176..aba42cc 100644 --- a/backend/apis/nodejs/api_controller.js +++ b/backend/apis/nodejs/api_controller.js @@ -3,7 +3,7 @@ const crypto = require('crypto'); const pgp = require('pg-promise')(); const Pool = require('pg-pool'); -const dbConfig = { +const database_configuration = { host: "localhost", port: 5432, database: "Blink", @@ -11,10 +11,7 @@ const dbConfig = { password: "postgres" }; -// Create a new connection pool -const db = pgp({ - pool: new Pool(dbConfig), -}); +const db = pgp(database_configuration); function register(req, res){ const userData = req.body; @@ -76,7 +73,7 @@ function register(req, res){ } async function register_async(req, res){ - console.log(process.env.DB_PASSWORD); + const userData = req.body; // 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); try{ - const result = await db.tx(async (t) => { + // Begin transaction + await db.tx(async (t) => { // Inserting in "Person" table const userInsertQuery = ` @@ -108,7 +106,7 @@ async function register_async(req, res){ ]); const activationLinkInsertQuery = ` - INSERT INTO "ActivationLink" (user_id, activation_code) + INSERT INTO "ActivationLink" (person_id, identifier) VALUES ($1, $2) RETURNING *`; @@ -116,7 +114,7 @@ async function register_async(req, res){ userResult.id, activationLink, ]); - return res.status(200).json({ user: userResult, activationLink: activationLinkResult }); + return res.status(200).json({ activationLink: activationLinkResult.identifier }); }); } catch (error){