Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set up market values get and post #15

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 16 additions & 74 deletions routes/valueRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,37 @@ const { db } = require('../server/db');

const valueRouter = express.Router();

// GET all items
valueRouter.get('/', async (req, res) => {
try {
const allValues = await db.query(`
SELECT *
FROM donation_tracking;
`);
res.status(200).send(allValues);
const allItems = await db.query(`SELECT * FROM fair_market_value;`);
res.status(200).send(allItems);
} catch (err) {
res.status(500).send(err.message);
}
});

valueRouter.get('/:id', async (req, res) => {
// GET all values by item id
valueRouter.get('/:itemId', async (req, res) => {
try {
const { id } = req.params;
const value = await db.query(
`
SELECT *
FROM donation_tracking
WHERE donation_id = $1;
`,
[id],
);
res.status(200).send(value);
const { itemId } = req.params;
const item = await db.query('SELECT * FROM fair_market_value WHERE item_id = $(itemId)', {
itemId,
});
res.status(200).send(item);
} catch (err) {
res.status(500).send(err.message);
}
});

valueRouter.delete('/:id', async (req, res) => {
// CREATE a new item
valueRouter.post('/', async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <consistent-return> reported by reviewdog 🐶
Expected to return a value at the end of async arrow function.

try {
const { id } = req.params;
await db.query('DELETE from donation_tracking WHERE donation_id = $1;', [id]);
res.status(200).send('Deleted donation');
} catch (err) {
res.status(500).send(err.message);
}
});

valueRouter.put('/:id', async (req, res) => {
try {
const { id } = req.params;
const {
businessId,
foodBankDonation,
reporter,
email,
date,
cannedDogFoodQuantity,
dryDogFoodQuantity,
cannedCatFoodQuantity,
dryCatFoodQuantity,
miscItems,
volunteerHours,
} = req.body;

const updatedValue = await db.query(
`UPDATE donation_tracking
SET donation_id = $(id)
${businessId ? `, business_id = $(businessId) ` : ''}
${foodBankDonation ? `, food_bank_donation = $(foodBankDonation) ` : ''}
${reporter ? `, reporter = $(reporter) ` : ''}
${email ? `, email = $(email) ` : ''}
${date ? `, date = $(date) ` : ''}
${cannedDogFoodQuantity ? `, canned_dog_food_quantity = $(cannedDogFoodQuantity) ` : ''}
${dryDogFoodQuantity ? `, dry_dog_food_quantity = $(dryDogFoodQuantity) ` : ''}
${cannedCatFoodQuantity ? `, canned_cat_food_quanitty = $(cannedCatFoodQuanitty) ` : ''}
${dryCatFoodQuantity ? `, dry_cat_food_quantity = $(dryCatFoodQuantity) ` : ''}
${miscItems ? `, misc_items = $(miscItems) ` : ''}
${volunteerHours ? `, volunteer_hours = $(volunteerHours) ` : ''}

WHERE id = $(id)
RETURNING *;`,
{
id,
businessId,
foodBankDonation,
reporter,
email,
date,
cannedDogFoodQuantity,
dryDogFoodQuantity,
cannedCatFoodQuantity,
dryCatFoodQuantity,
miscItems,
volunteerHours,
},
const { itemName, quantityType, quantity, price } = req.body;
const newItem = await db.query(
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <no-unused-vars> reported by reviewdog 🐶
'newItem' is assigned a value but never used.

'INSERT INTO fair_market_value (item_name, quantity_type, quantity, price) VALUES ($(itemName), $(quantityType), $(quantity), $(price)) RETURNING *',
{ itemName, quantityType, quantity, price },
);
return res.status(200).send(updatedValue);
} catch (err) {
return res.status(500).send(err.message);
}
Expand Down
Loading