I have the following code.
routes/index.js:
const express = require('express');
const router = express.Router();
const weeklyReportsController = require('../controllers/weeklyReportsController');
router.get('/weekly_reports', weeklyReportsController);
module.exports = router;
controllers/weeklyReportsController.js:
const weeklyReportsService = require('../services/weeklyReportsService');
const weeklyReportsController = async (req, res) => {
try {
const data = await weeklyReportsService;
res.json({data})
console.log('Weekly reports controller - success');
} catch(err) {
console.log(err);
}
};
module.exports = weeklyReportsController;
services/weeklyReportsService.js:
const Pool = require('pg').Pool
const pool = new Pool({connection data})
const weeklyReportsService = async () => {
const res = await pool.query('SELECT * FROM reports', (err, results) => {
if (err) {
throw err;
} else {
console.log('Weekly reports service - success.');
}
return res.status(200).json(results.rows);
});
};
module.exports = weeklyReportsService;
All I am returning by visiting localhost:8080/api/weekly_reports is an empty JSON object of {}. I tried adding some console.log() methods to my code to see what was triggering and what wasn't, and the log from my service is not being set off. I have spent a couple hours trying to dig through example codes, reading documentation, and honestly just looking blankly at my screen - I just can't figure out what I did wrong here.
Does anyone have a suggestion as to what I am doing wrong here?
Thank you all for your time and if there is anything I can add for clarity, please don't hesitate to ask and I will provide it.
Thank you for your help.
EDIT: The data is sitting in a Postgres database called reports with the table also called reports.