const express = require('express');
const router = express.Router();
const pool = require("../db");
require("dotenv").config();


const BASE_URL = process.env.BASE_URL;

router.get("/about", async (req, res) => {
    try {
        // Queries
        const aboutQuery = `SELECT * FROM about`;

        // Perform queries correctly
        const aboutRaw = await pool.query(aboutQuery);

        // Log the entire result to see the structure
        console.log("About Raw Result:", aboutRaw);

        // If rows exist, proceed with mapping
        const updatedAbout = aboutRaw?.map(about => ({
            ...about,
            image: about.image ? BASE_URL + about.image : null
        })) || [];

        //console.log("Updated about me: ", updatedAbout);

        // Send response
        res.json(updatedAbout);

    } catch (err) {
        console.error("Error fetching intro:", err.message);
        res.status(500).send("Server error");
    }
});

module.exports = router;