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