2018-12-20 19:13:56 +00:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-12-20 19:13:53 +00:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2018-12-20 19:13:59 +00:00
|
|
|
let Router
|
|
|
|
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
|
|
|
|
|
|
|
module.exports = Router = {
|
|
|
|
route(app) {
|
2020-08-10 16:01:11 +00:00
|
|
|
app.param('project_id', function (req, res, next, project_id) {
|
2018-12-20 19:13:59 +00:00
|
|
|
if (ObjectId.isValid(project_id)) {
|
|
|
|
return next()
|
|
|
|
} else {
|
2020-03-06 18:33:17 +00:00
|
|
|
return res.status(400).send('Invalid project_id')
|
2018-12-20 19:13:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
app.param('thread_id', function (req, res, next, thread_id) {
|
2018-12-20 19:13:59 +00:00
|
|
|
if (ObjectId.isValid(thread_id)) {
|
|
|
|
return next()
|
|
|
|
} else {
|
2020-03-06 18:33:17 +00:00
|
|
|
return res.status(400).send('Invalid thread_id')
|
2018-12-20 19:13:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// These are for backwards compatibility
|
|
|
|
app.get(
|
|
|
|
'/room/:project_id/messages',
|
|
|
|
MessageHttpController.getGlobalMessages
|
|
|
|
)
|
|
|
|
app.post(
|
|
|
|
'/room/:project_id/messages',
|
|
|
|
MessageHttpController.sendGlobalMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/project/:project_id/messages',
|
|
|
|
MessageHttpController.getGlobalMessages
|
|
|
|
)
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/messages',
|
|
|
|
MessageHttpController.sendGlobalMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/thread/:thread_id/messages',
|
|
|
|
MessageHttpController.sendThreadMessage
|
|
|
|
)
|
|
|
|
app.get('/project/:project_id/threads', MessageHttpController.getAllThreads)
|
|
|
|
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/thread/:thread_id/messages/:message_id/edit',
|
|
|
|
MessageHttpController.editMessage
|
|
|
|
)
|
2020-03-06 18:33:17 +00:00
|
|
|
app.delete(
|
2018-12-20 19:13:59 +00:00
|
|
|
'/project/:project_id/thread/:thread_id/messages/:message_id',
|
|
|
|
MessageHttpController.deleteMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/thread/:thread_id/resolve',
|
|
|
|
MessageHttpController.resolveThread
|
|
|
|
)
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/thread/:thread_id/reopen',
|
|
|
|
MessageHttpController.reopenThread
|
|
|
|
)
|
2020-03-06 18:33:17 +00:00
|
|
|
app.delete(
|
2018-12-20 19:13:59 +00:00
|
|
|
'/project/:project_id/thread/:thread_id',
|
|
|
|
MessageHttpController.deleteThread
|
|
|
|
)
|
|
|
|
|
|
|
|
return 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
|
|
|
}
|