2018-12-20 14:13:59 -05:00
|
|
|
const MessageHttpController = require('./Features/Messages/MessageHttpController')
|
2020-08-19 08:00:01 -04:00
|
|
|
const { ObjectId } = require('./mongodb')
|
2018-12-20 14:13:59 -05:00
|
|
|
|
2022-01-06 11:32:46 -05:00
|
|
|
module.exports = {
|
2018-12-20 14:13:59 -05:00
|
|
|
route(app) {
|
2022-01-06 11:32:46 -05:00
|
|
|
app.param('projectId', function (req, res, next, projectId) {
|
|
|
|
if (ObjectId.isValid(projectId)) {
|
2022-01-07 05:41:23 -05:00
|
|
|
next()
|
2018-12-20 14:13:59 -05:00
|
|
|
} else {
|
2022-01-07 05:41:23 -05:00
|
|
|
res.status(400).send('Invalid projectId')
|
2018-12-20 14:13:59 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-01-06 11:32:46 -05:00
|
|
|
app.param('threadId', function (req, res, next, threadId) {
|
|
|
|
if (ObjectId.isValid(threadId)) {
|
2022-01-07 05:41:23 -05:00
|
|
|
next()
|
2018-12-20 14:13:59 -05:00
|
|
|
} else {
|
2022-01-07 05:41:23 -05:00
|
|
|
res.status(400).send('Invalid threadId')
|
2018-12-20 14:13:59 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// These are for backwards compatibility
|
|
|
|
app.get(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/room/:projectId/messages',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.getGlobalMessages
|
|
|
|
)
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/room/:projectId/messages',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.sendGlobalMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.get(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/messages',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.getGlobalMessages
|
|
|
|
)
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/messages',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.sendGlobalMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId/messages',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.sendThreadMessage
|
|
|
|
)
|
2022-01-06 11:32:46 -05:00
|
|
|
app.get('/project/:projectId/threads', MessageHttpController.getAllThreads)
|
2018-12-20 14:13:59 -05:00
|
|
|
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId/messages/:messageId/edit',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.editMessage
|
|
|
|
)
|
2020-03-06 13:33:17 -05:00
|
|
|
app.delete(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId/messages/:messageId',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.deleteMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId/resolve',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.resolveThread
|
|
|
|
)
|
|
|
|
app.post(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId/reopen',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.reopenThread
|
|
|
|
)
|
2020-03-06 13:33:17 -05:00
|
|
|
app.delete(
|
2022-01-06 11:32:46 -05:00
|
|
|
'/project/:projectId/thread/:threadId',
|
2018-12-20 14:13:59 -05:00
|
|
|
MessageHttpController.deleteThread
|
|
|
|
)
|
|
|
|
|
2022-01-07 05:41:23 -05:00
|
|
|
app.get('/status', (req, res, next) => res.send('chat is alive'))
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2018-12-20 14:13:59 -05:00
|
|
|
}
|