Skip to content

Commit

Permalink
Merge pull request #60 from andela/ch-notifications-timestamp-169749860
Browse files Browse the repository at this point in the history
#169749860 - Add timestamp field to notifications
  • Loading branch information
nakiwuge committed Nov 15, 2019
2 parents d4f3169 + 0ebebaa commit c7074bc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/controllers/commentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class CommentsController {
const notification = await notifBuilder(
request,
userNotiified,
`A comment has been made on request ${requestId}. Click here to view: ${APP_URL_BACKEND}/api/v1/requests/${requestId}.`
`A comment has been made on request ${requestId}. Click here to view: ${APP_URL_BACKEND}/api/v1/requests/${requestId}.`,
);
await notifSaver(notification);
const {
Expand Down
15 changes: 15 additions & 0 deletions src/database/migrations/20191113182004-addTimeNotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.sequelize.transaction(t => Promise.all([
queryInterface.addColumn('notifications', 'timestamp', {
type: Sequelize.TIME,
}, { transaction: t }),
queryInterface.addColumn('bookingNotifications', 'timestamp', {
type: Sequelize.TIME,
}, { transaction: t }),
])),

down: queryInterface => queryInterface.sequelize.transaction(t => Promise.all([
queryInterface.removeColumn('notifications', 'timestamp', { transaction: t }),
queryInterface.removeColumn('bookingNotifications', 'timestamp', { transaction: t }),
])),
};
4 changes: 4 additions & 0 deletions src/database/models/bookingnotifications.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

'use strict';
module.exports = (sequelize, DataTypes) => {
const bookingNotifications = sequelize.define('bookingNotifications', {
Expand All @@ -8,6 +9,9 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
timestamp: {
type: DataTypes.TIME,
},
}, {
tableName: 'bookingNotifications'
});
Expand Down
4 changes: 4 additions & 0 deletions src/database/models/notifications.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

'use strict';
module.exports = (sequelize, DataTypes) => {
const notifications = sequelize.define('notifications', {
requestId: DataTypes.INTEGER,
userNotified: DataTypes.INTEGER,
activity: DataTypes.STRING,
timestamp: {
type: DataTypes.TIME,
},
isRead: {
type: DataTypes.BOOLEAN,
defaultValue: false,
Expand Down
25 changes: 15 additions & 10 deletions src/database/seeders/20191028170529-notificationsTableSeeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,47 @@ module.exports = {
{
requestId: 2,
userNotified: 8,
activity: 'created',
activity: 'A request has been created. Click here to view: https://caret-bn-backend-staging.herokuapp.com/api/v1/requests/2.',
isRead: false,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
timestamp: new Date()
},
{
requestId: 2,
userNotified: 3,
activity: 'rejected',
activity: 'A request has been rejected. Click here to view: https://caret-bn-backend-staging.herokuapp.com/api/v1/requests/2.',
isRead: true,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
timestamp: new Date()
},
{
requestId: 2,
userNotified: 3,
activity: 'approved',
activity: 'A request has been approved. Click here to view: https://caret-bn-backend-staging.herokuapp.com/api/v1/requests/2.',
isRead: false,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
timestamp: new Date()
},
{
requestId: 2,
userNotified: 3,
activity: 'approved',
activity: 'A request has been approved. Click here to view: https://caret-bn-backend-staging.herokuapp.com/api/v1/requests/2.',
isRead: false,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
timestamp: new Date()
},
{
requestId: 2,
userNotified: 3,
activity: 'approved',
activity: 'A request has been approved. Click here to view: https://caret-bn-backend-staging.herokuapp.com/api/v1/requests/2.',
isRead: false,
createdAt: new Date(),
updatedAt: new Date()
updatedAt: new Date(),
timestamp: new Date()
},

])
Expand Down
3 changes: 3 additions & 0 deletions src/services/bookingNotifServices.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import moment from 'moment';
import models from '../database/models';

export default class bookingNotifServices {
Expand All @@ -22,10 +23,12 @@ export default class bookingNotifServices {
}

static async bookingNotifBuilder(booking, userNotified, activity) {
const timestamp = moment().format('HH:mm:ss');
const notification = await models.bookingNotifications.build({
bookingId: booking.id,
userNotified,
activity,
timestamp,
});
return notification;
}
Expand Down
3 changes: 3 additions & 0 deletions src/services/notifServices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable require-jsdoc */
import moment from 'moment';
import models from '../database/models';

export default class notifServices {
Expand Down Expand Up @@ -43,10 +44,12 @@ export default class notifServices {
}

static async notifBuilder(request, userNotified, activity) {
const timestamp = moment().format('HH:mm:ss');
const notification = await models.notifications.build({
requestId: request.id,
userNotified,
activity,
timestamp,
});
return notification;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/db/queries/notificationQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const userNotidicationQuery = userId => {
userNotified: userId
},
attributes: [
'id', 'activity', 'isRead', 'createdAt', 'updatedAt'
'id', 'activity', 'isRead', 'createdAt', 'timestamp', 'updatedAt'
],
include: [
{
Expand Down

0 comments on commit c7074bc

Please sign in to comment.