-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #483 from timeoff-management/tom-xxx-notification-…
…bell Expose notification bell in the header
- Loading branch information
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
"use strict"; | ||
|
||
const | ||
express = require('express'), | ||
router = express.Router(); | ||
|
||
|
||
const NOTIFICATION_TYPE_PENDING_REQUESTS = 'pending_request'; | ||
|
||
/** | ||
* Factory method that created a notification of given type | ||
*/ | ||
const newNotification = ({type, value}) => { | ||
|
||
if (type === NOTIFICATION_TYPE_PENDING_REQUESTS) { | ||
return { | ||
type, | ||
numberOfRequests: value, | ||
label: (value === 1 ? 'A leave request to process' : `${value} leave requests to process`), | ||
link: '/requests/', | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
router.get('/notifications/', async (req, res) => { | ||
const actingUser = req.user; | ||
|
||
const data = []; | ||
|
||
try { | ||
const leaves = await actingUser.promise_leaves_to_be_processed(); | ||
|
||
if (leaves.length > 0) { | ||
data.push(newNotification({type: NOTIFICATION_TYPE_PENDING_REQUESTS, value: leaves.length})); | ||
} | ||
|
||
res.json({data}); | ||
} catch (error) { | ||
console.log(`Failed to fetch notifications for user [${actingUser.id}]: ${error} at ${error.stack}`); | ||
res.json({ error: 'Failed to fetch notifications.' }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters