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

backend for fix notification drawer #28

Merged
merged 1 commit into from
Apr 20, 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
18 changes: 12 additions & 6 deletions routes/notificationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ notificationRouter.get('/:id', async (req, res) => {
});

notificationRouter.post('/', async (req, res) => {
const { business_id: businessId, message, timestamp, been_dismissed: beenDismissed } = req.body;
const {
business_id: businessId,
message,
timestamp,
been_dismissed: beenDismissed,
type,
} = req.body;
try {
await db.query(
`
INSERT INTO notification (business_id, message, timestamp, been_dismissed)
INSERT INTO notification (business_id, message, timestamp, been_dismissed, type)
VALUES
($(businessId), $(message), $(timestamp), $(beenDismissed));
($(businessId), $(message), $(timestamp), $(beenDismissed), $(type));
`,
{ businessId, message, timestamp, beenDismissed },
{ businessId, message, timestamp, beenDismissed, type },
);
res.status(200).json({
status: 'Success',
Expand Down Expand Up @@ -78,10 +84,10 @@ notificationRouter.put('/:id', async (req, res) => {
notificationRouter.get('/request/:id', async (req, res) => {
const { id } = req.params;

const message = `'Business ID: ${id} is requesting:%'`;
const message = `'Business ID: ${id}%'`;

const idNotification = await db.query(
`SELECT * FROM notification WHERE business_id = 0 AND message LIKE ${message} ORDER BY timestamp DESC;`,
`SELECT * FROM notification WHERE business_id = 0 AND message LIKE ${message} AND type='Supply Request' ORDER BY timestamp DESC;`,
{
id,
},
Expand Down
Loading