diff --git a/client/components/admin/Notifications.jsx b/client/components/admin/Notifications.jsx index 75753d8..7ddf33a 100644 --- a/client/components/admin/Notifications.jsx +++ b/client/components/admin/Notifications.jsx @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Row, Col } from 'react-materialize'; +import moment from 'moment'; /** * displays admin notifications @@ -16,7 +17,7 @@ const Notifications = (props) => { >

{notification.bookTitle} {notification.type}ed - by {notification.username} + by {notification.username} {moment(notification.createdAt).fromNow()}

) diff --git a/server/controllers/books.js b/server/controllers/books.js index b58b6f3..a08b55e 100644 --- a/server/controllers/books.js +++ b/server/controllers/books.js @@ -257,6 +257,12 @@ export default { .then(() => { book.total -= 1; book.save(); // wait till book is saved before sending response + const notification = new Notification({ + type: 'borrow', + bookTitle: book.title, + username: req.user.username, + }); + notification.save(); }) .then(() => res.status(200).send({ message: `You have successfully borrowed ${book.title}` +