-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(booking and travel notifications):add a userId column in the accom…
…modation table refactor the existing notification code to ensure reusability Add notification functionality to the trip and booking controller. [Starts #169258639]
- Loading branch information
Showing
35 changed files
with
739 additions
and
176 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
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,35 @@ | ||
|
||
import dotenv from 'dotenv'; | ||
import Response from '../helpers/Response'; | ||
import NotificationService from '../services/NotificationService'; | ||
|
||
const { markNotificationAsRead } = NotificationService; | ||
dotenv.config(); | ||
/** | ||
* @exports | ||
* @class AccommodationController | ||
*/ | ||
class AccommodationController { | ||
/** | ||
* Travel Admin can be able to create accommodation facility | ||
* @static | ||
* @param {object} req request object | ||
* @param {object} res response object | ||
* @memberof AccommodationController | ||
* @returns {object} data | ||
*/ | ||
static async markNotificationsAsRead(req, res) { | ||
try { | ||
const { notificationIds } = req.body; | ||
const notificationArr = req.params.notificationId | ||
? notificationIds.filter(id => id === parseInt(req.params.notificationId, 10)) | ||
: notificationIds; | ||
await markNotificationAsRead(notificationArr); | ||
return Response.successMessage(req, res, 'Notification marked as read successfully', '', 201); | ||
} catch (err) { | ||
return Response.errorMessage(req, res, 'Server Error', 500); | ||
} | ||
} | ||
} | ||
|
||
export default AccommodationController; |
24 changes: 24 additions & 0 deletions
24
src/database/migrations/20191203092338-accommodations-add-userId.js
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,24 @@ | ||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return queryInterface.describeTable('accommodations').then(tableDefinition => { | ||
if (!tableDefinition['userId']){ | ||
return queryInterface.addColumn('accommodations', 'userId', { | ||
type: Sequelize.INTEGER, | ||
allowNull: true, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'users', | ||
key: 'id' | ||
} } ); | ||
} else { | ||
return Promise.resolve(true); | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('accommodations'); | ||
} | ||
} | ||
|
||
|
24 changes: 24 additions & 0 deletions
24
src/database/migrations/20191203223955-add-booking-Id-notification.js
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,24 @@ | ||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return queryInterface.describeTable('notifications').then(tableDefinition => { | ||
if (!tableDefinition['bookingId']){ | ||
return queryInterface.addColumn('notifications', 'bookingId', { | ||
type: Sequelize.INTEGER, | ||
allowNull: true, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'bookings', | ||
key: 'id' | ||
} } ); | ||
} else { | ||
return Promise.resolve(true); | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('notifications'); | ||
} | ||
} | ||
|
||
|
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
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
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
import eventEmitters from './eventEmitters'; | ||
|
||
const notificationEvents = (eventName, clientData) => { | ||
eventEmitters.emit(eventName, JSON.stringify(clientData)); | ||
}; | ||
|
||
const sendNotification = (io, emitterEvent, socketEvent) => { | ||
io.on('connection', (socket) => { | ||
eventEmitters.on(emitterEvent, (data) => { | ||
socket.emit(socketEvent, data); | ||
}); | ||
}); | ||
}; | ||
|
||
export { | ||
notificationEvents, | ||
sendNotification | ||
}; |
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
Oops, something went wrong.