forked from wholespace214/crash-game-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ML-139 event resolve and cancel emit user message
- Loading branch information
1 parent
fd3de13
commit 194cb97
Showing
14 changed files
with
370 additions
and
161 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,57 @@ | ||
const websocketService = require('../services/websocket-service'); | ||
const chatMessageService = require('../services/chat-message-service'); | ||
const eventService = require('../services/event-service'); | ||
const _ = require('lodash'); | ||
|
||
exports.getMessagesByUser = async (req, res) => { | ||
const skip = req.query.skip ? +req.query.skip : 0; | ||
const limit = req.query.limit ? +req.query.limit : 20; | ||
|
||
const messages = await chatMessageService.getLatestChatMessagesByUserId( | ||
req.user._id, | ||
limit, | ||
skip | ||
); | ||
|
||
res.status(200).json({ | ||
messages: messages?.data || [], | ||
total: messages?.total || 0, | ||
}); | ||
}; | ||
|
||
exports.setMessageRead = async (req, res) => { | ||
const { id } = req.params; | ||
const requestingUser = req.user; | ||
await chatMessageService.setMessageRead(id, requestingUser); | ||
return res.status(200).send(); | ||
}; | ||
|
||
exports.sendMessage = async (req, res) => { | ||
// console.log('sending a test message'); | ||
|
||
// // SEND OASIS EVENT RESOLVED | ||
// setTimeout(async () => { | ||
// const event = await eventService.getEvent('61792b2bc986908179b4e4b5'); | ||
// event.bookmarks.map(async (u) => { | ||
// await websocketService.emitBetResolveNotification(u, event, event.bets[0], 0, 100); | ||
// }); | ||
// }, 2000); | ||
|
||
// // SEND ELON EVENT RESOLVED | ||
// setTimeout(async () => { | ||
// const event = await eventService.getEvent('617950d40a97aa8c14679fd0'); | ||
// event.bookmarks.map(async (u) => { | ||
// await websocketService.emitBetResolveNotification(u, event, event.bets[0], 0, 0); | ||
// }); | ||
// }, 4500); | ||
|
||
// // SEND UEFA CANCELLED | ||
// setTimeout(async () => { | ||
// const event = await eventService.getEvent('61797d87fce07aa1dfc00b5c'); | ||
// event.bookmarks.map(async (u) => { | ||
// await websocketService.emitEventCancelNotification(u, event, event.bets[0]); | ||
// }); | ||
// }, 18000); | ||
|
||
return res.status(200).send({}); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
const router = require('express').Router(); | ||
const { check } = require('express-validator'); | ||
const chatsController = require('../../controllers/chats-controller'); | ||
const { validateRequest } = require('../../util/request-validator'); | ||
|
||
router.get( | ||
'/chat-messages/:roomId', | ||
[check('roomId').notEmpty()], | ||
chatsController.getChatMessagesByRoom, | ||
[check('roomId').notEmpty(), check('roomId').isMongoId()], | ||
validateRequest(chatsController.getChatMessagesByRoom) | ||
); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const router = require('express').Router(); | ||
const { check } = require('express-validator'); | ||
const { validateRequest } = require('../../util/request-validator'); | ||
const controller = require('../../controllers/user-messages-controller'); | ||
|
||
router.get('/', controller.getMessagesByUser); | ||
|
||
router.put('/:id/read', [check('id').isMongoId()], validateRequest(controller.setMessageRead)); | ||
|
||
router.post( | ||
'/', | ||
[check('userId').exists(), check('userId'.isMongoId)], | ||
validateRequest(controller.sendMessage) | ||
); | ||
|
||
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
Oops, something went wrong.