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

setup_values_get_put_delete Issue #11 Resolved #16

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions .github/workflows/scripts/reviewReviewed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ const messageAssignee = async ({ context }) => {
try {
const UserModel = getUserModel();
const slackAssignees = await Promise.allSettled(
githubAssignees.map(assignee => UserModel.findOne({ github: assignee.login })),
githubAssignees.map((assignee) => UserModel.findOne({ github: assignee.login })),
);
if (context.payload.review.state === 'approved') {
await Promise.all(
slackAssignees.map(assignee =>
slackAssignees.map((assignee) =>
Bot.client.chat.postMessage({
channel: assignee.value?.slackId,
text: `One of your pull requests has been APPROVED by ${reviewer}! <${url}|View Review> :shrek::thumbsup:`,
Expand All @@ -53,7 +53,7 @@ const messageAssignee = async ({ context }) => {
);
} else {
await Promise.all(
slackAssignees.map(assignee =>
slackAssignees.map((assignee) =>
Bot.client.chat.postMessage({
channel: assignee.value?.slackId,
text: `One of your pull requests has been REVIEWED by ${reviewer}! <${url}|View Review> :shrek:`,
Expand Down
7 changes: 3 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ require('dotenv').config();
const businessRouter = require('./routes/businessRouter');
// const donationRouter = require('./routes/donationRouter');
// const notificationRouter = require('./routes/notificationRouter');
// const valueRouter = require('./routes/valueRouter');
const valueRouter = require('./routes/valueRouter');

const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
Copy link
Member

Choose a reason for hiding this comment

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

make sure to pull in the code next time before you work, otherwise we will lose some code


const PORT = process.env.PORT || 3001;

app.use(
Expand All @@ -23,7 +22,7 @@ app.use(
app.use('/business', businessRouter);
// app.use('/donation', donationRouter);
// app.use('/notification', notificationRouter);
// app.use('/value', valueRouter);
app.use('/value', valueRouter);

app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
Expand Down
125 changes: 121 additions & 4 deletions routes/valueRouter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,123 @@
// const express = require('express');
// const { db } = require('../server/db');
const express = require('express');
const { db } = require('../server/db');

// Your code below (delete this line when committing):
const valueRouter = express.Router();

// const valueRouter = express.Router();
valueRouter.get('/', async (req, res) => {
try {
const allValues = await db.query(`
SELECT *
FROM business;
`);
res.status(200).send(allValues);
} catch (err) {
res.status(500).send(err.message);
}
});

valueRouter.get('/:id', 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);
} catch (err) {
res.status(500).send(err.message);
}
});

valueRouter.delete('/:id', async (req, res) => {
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 {
Copy link
Member

Choose a reason for hiding this comment

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

const { business_id: businessId, message, timestamp, been_dismissed: beenDismissed } = req.body;

do it like so, we redefine the snake case into camel case so that we have consistent variables across our different code packages

business_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'business_id' is not in camel case.

donation_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'donation_id' is not in camel case.

food_bank_donation,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'food_bank_donation' is not in camel case.

reporter,
email,
date,
canned_dog_food_quantity,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_dog_food_quantity' is not in camel case.

dry_dog_food_quantity,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_dog_food_quantity' is not in camel case.

canned_cat_food_quantity,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_cat_food_quantity' is not in camel case.

dry_cat_food_quantity,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_cat_food_quantity' is not in camel case.

misc_items,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'misc_items' is not in camel case.

volunteer_hours,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'volunteer_hours' is not in camel case.

} = req.body;
if (!business_id) throw new Error('business_id is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'business_id' is not in camel case.

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this, we will be doing frontend validation instead.

if (!donation_id) throw new Error('donation_id line is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'donation_id' is not in camel case.

if (!food_bank_donation) throw new Error('food_bank_donation is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'food_bank_donation' is not in camel case.

if (!reporter) throw new Error('business_id is required.');
if (!email) throw new Error('donation_id line is required.');
if (!date) throw new Error('food_bank_donation is required.');
if (!canned_dog_food_quantity) throw new Error('canned_dog_food_quantity is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_dog_food_quantity' is not in camel case.

if (!dry_dog_food_quantity) throw new Error('dry_dog_food_quantity line is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_dog_food_quantity' is not in camel case.

if (!canned_cat_food_quantity) throw new Error('canned_cat_food_quanitty is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_cat_food_quantity' is not in camel case.

if (!dry_cat_food_quantity) throw new Error('dry_cat_food_quantity is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_cat_food_quantity' is not in camel case.

if (!misc_items) throw new Error('misc_items line is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'misc_items' is not in camel case.

if (!volunteer_hours) throw new Error('volunteer_hours is required.');
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'volunteer_hours' is not in camel case.

Copy link
Member

Choose a reason for hiding this comment

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

Please remove all of these "is required" lines", we will be doing frontend validation instead.


const updatedValue = await db.query(
`UPDATE donation_tracking
SET donation_id = $(id)
${business_id ? `, business_id = $(business_id) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'business_id' is not in camel case.

${donation_id ? `, donation_id = $(donation_id) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'donation_id' is not in camel case.

Copy link
Member

@Madhu2244 Madhu2244 Dec 6, 2023

Choose a reason for hiding this comment

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

This line is redundant with the `SET donation_id = $(id) part

${food_bank_donation ? `, food_bank_donation = $(food_bank_donation) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'food_bank_donation' is not in camel case.

${reporter ? `, reporter = $(reporter) ` : ''}
${email ? `, email = $(email) ` : ''}
${date ? `, date = $(date) ` : ''}
${
canned_dog_food_quantity
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_dog_food_quantity' is not in camel case.

? `, canned_dog_food_quantity = $(canned_dog_food_quantity) `
: ''
}
${dry_dog_food_quantity ? `, dry_dog_food_quantity = $(dry_dog_food_quantity) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_dog_food_quantity' is not in camel case.

${
canned_cat_food_quantity
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'canned_cat_food_quantity' is not in camel case.

? `, canned_cat_food_quanitty = $(canned_cat_food_quanitty) `
: ''
}
${dry_cat_food_quantity ? `, dry_cat_food_quantity = $(dry_cat_food_quantity) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'dry_cat_food_quantity' is not in camel case.

${misc_items ? `, misc_items = $(misc_items) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'misc_items' is not in camel case.

${volunteer_hours ? `, volunteer_hours = $(volunteer_hours) ` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'volunteer_hours' is not in camel case.


WHERE id = $(id)
RETURNING *;`,
{
id,
business_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'business_id' is not in camel case.

donation_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'donation_id' is not in camel case.

food_bank_donation,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <camelcase> reported by reviewdog 🐶
Identifier 'food_bank_donation' is not in camel case.

reporter,
email,
date,
canned_dog_food_quantity,
dry_dog_food_quantity,
canned_cat_food_quantity,
dry_cat_food_quantity,
misc_items,
volunteer_hours,
},
);
return res.status(200).send(updatedValue);
} catch (err) {
return res.status(500).send(err.message);
}
});

module.exports = valueRouter;