Skip to content

Commit

Permalink
chore: remove duped route
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Aug 9, 2024
1 parent de56d3d commit 84cdfff
Showing 1 changed file with 2 additions and 62 deletions.
64 changes: 2 additions & 62 deletions routes/donationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ donationRouter.get('/totalDonations', async (req, res) => {
});

// GET CSV donation selecting by id
// eslint-disable-next-line consistent-return
donationRouter.get('/:tableName/selectByIds', async (req, res) => {
try {
const { tableName } = req.params;
Expand All @@ -52,7 +51,6 @@ donationRouter.get('/:tableName/selectByIds', async (req, res) => {
`);

if (!tableExists[0].exists) {
console.log(`Table '${tableName}' does not exist.`);
return res.status(404).send(`Table '${tableName}' does not exist.`);
}

Expand Down Expand Up @@ -84,10 +82,9 @@ donationRouter.get('/:tableName/selectByIds', async (req, res) => {
rows = await db.query(query);
}

res.status(200).send(rows);
return res.status(200).send(rows);
} catch (err) {
console.error('Error:', err);
res.status(500).send(err.message);
return res.status(500).send(err.message);
}
});

Expand All @@ -107,63 +104,6 @@ donationRouter.get('/:donationId', async (req, res) => {
}
});

// GET CSV donation selecting by id
donationRouter.get('/:tableName/selectByIds', async (req, res) => {
try {
const { tableName } = req.params;
const { ids } = req.query;
let rows;

// Check if the table name is valid and exists in the database
const tableExists = await db.query(`
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = '${tableName}'
);
`);

if (!tableExists[0].exists) {
console.log(`Table '${tableName}' does not exist.`);
return res.status(404).send(`Table '${tableName}' does not exist.`);
}

// Convert the comma-separated IDs string to an array
const idsArray = ids.split(',');
// Construct the SQL query based on the provided IDs

if (tableName === 'donation_tracking') {
const query = `
SELECT *
FROM ${tableName}
WHERE donation_id IN (${idsArray.map((id) => `'${id}'`).join(',')});
`;
rows = await db.query(query);
} else if (tableName === 'notification') {
const query = `
SELECT *
FROM ${tableName}
WHERE notifcation_id IN (${idsArray.map((id) => `'${id}'`).join(',')});
`;
rows = await db.query(query);
} else {
// if table is business
const query = `
SELECT *
FROM ${tableName}
WHERE id IN (${idsArray.map((id) => `'${id}'`).join(',')});
`;
rows = await db.query(query);
}

res.status(200).send(rows);
return undefined;
} catch (err) {
console.error('Error:', err);
res.status(500).send(err.message);
return undefined;
}
});

donationRouter.get('/business/:businessId', async (req, res) => {
try {
const { businessId } = req.params;
Expand Down

0 comments on commit 84cdfff

Please sign in to comment.