Skip to content

Conversation

@mdsaad31
Copy link
Owner

@mdsaad31 mdsaad31 commented Jul 7, 2025

No description provided.

@netlify
Copy link

netlify bot commented Jul 7, 2025

Deploy Preview for excel-data-analytics ready!

Name Link
🔨 Latest commit b956682
🔍 Latest deploy log https://app.netlify.com/projects/excel-data-analytics/deploys/686baa20d35e6f00086ba33b
😎 Deploy Preview https://deploy-preview-5--excel-data-analytics.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mdsaad31 mdsaad31 requested a review from Copilot October 18, 2025 09:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates history storage and retrieval from a local Express/MongoDB setup to PostgreSQL via Netlify Functions.

  • Replace Mongoose model and Express server with pg Pool and serverless-http-wrapped Express app under Netlify Functions.
  • Update client endpoints to call Netlify Function routes and switch identifiers from _id to id.
  • Add Netlify configuration and a bootstrap DB script that ensures the file_history table exists.

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/pages/History.jsx Point history fetch/delete to Netlify Functions; switch key usage from _id to id.
src/components/excel/ExcelUploader.jsx Post history entries to Netlify Function (path updated).
server/routes/history.js Replace Mongoose queries with PostgreSQL queries via pg Pool.
server/db.js Initialize pg Pool and ensure file_history table exists.
server/api.js Create serverless Express function and mount history routes.
server/package.json Add server-side dependencies for functions runtime.
package.json Swap Mongo/Mongoose for pg and serverless-http at the root.
netlify.toml Configure Netlify Functions directory and plugin.
server/models/fileHistory.model.js Remove Mongoose model (no longer used).
server/index.js Remove standalone Express server (replaced by Netlify Function).
server/hello.js Add sample Netlify Function.
Files not reviewed (2)
  • pnpm-lock.yaml: Language not supported
  • server/package-lock.json: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

};

await axios.post('http://localhost:5000/history/add', historyData);
await axios.post('/.netlify/functions/history/add', historyData);
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Netlify Function entry point is server/api.js, so the correct endpoint prefix is "/.netlify/functions/api". This call will 404 as written. Update the URL to "/.netlify/functions/api/history/add".

Suggested change
await axios.post('/.netlify/functions/history/add', historyData);
await axios.post('/.netlify/functions/api/history/add', historyData);

Copilot uses AI. Check for mistakes.
try {
const history = await FileHistory.find({ user: req.query.user });
res.json(history);
const { rows } = await pool.query('SELECT * FROM file_history WHERE "user" = $1 ORDER BY uploadDate DESC', [req.query.user]);
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning raw PostgreSQL column names will break the existing client, which references fileName and uploadDate (camelCase). Alias the columns in the SELECT to preserve the API contract and order by the actual column name (uploaddate) to avoid relying on aliases in ORDER BY.
Suggested change:
const { rows } = await pool.query(
'SELECT id, filename AS "fileName", uploaddate AS "uploadDate", size, "user" FROM file_history WHERE "user" = $1 ORDER BY uploaddate DESC',
[req.query.user]
);

Suggested change
const { rows } = await pool.query('SELECT * FROM file_history WHERE "user" = $1 ORDER BY uploadDate DESC', [req.query.user]);
const { rows } = await pool.query(
'SELECT id, filename AS "fileName", uploaddate AS "uploadDate", size, "user" FROM file_history WHERE "user" = $1 ORDER BY uploaddate DESC',
[req.query.user]
);

Copilot uses AI. Check for mistakes.
Comment on lines 76 to 78
<td className="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<p className="text-gray-900 whitespace-no-wrap">{item.fileName}</p>
</td>
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the switch to PostgreSQL, the returned row keys will be lowercase (filename/uploaddate) unless aliased. Either update this reference to item.filename, or adopt the server-side aliasing in server/routes/history.js (see prior comment) to keep item.fileName working.

Copilot uses AI. Check for mistakes.
"dependencies": {
"pg": "^8.12.0",
"dotenv": "^17.0.0",
"express": "^5.1.0"
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server/api.js requires serverless-http, but it's not declared in server/package.json. Since the functions directory is set to "server", declare serverless-http here to avoid module resolution issues during Netlify Functions build/runtime.

Suggested change
"express": "^5.1.0"
"express": "^5.1.0",
"serverless-http": "^3.0.0"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant