overleaf/services/chat/app/js/router.js
Eric Mc Sween 0a12c47b35 Merge pull request #10815 from overleaf/em-esm-chat
Move chat service to ES modules

GitOrigin-RevId: c08ae8328b8f3b539e6cfe052834b84bb3756330
2022-12-14 09:03:03 +00:00

65 lines
1.8 KiB
JavaScript

import * as MessageHttpController from './Features/Messages/MessageHttpController.js'
import { ObjectId } from './mongodb.js'
export function route(app) {
app.param('projectId', function (req, res, next, projectId) {
if (ObjectId.isValid(projectId)) {
next()
} else {
res.status(400).send('Invalid projectId')
}
})
app.param('threadId', function (req, res, next, threadId) {
if (ObjectId.isValid(threadId)) {
next()
} else {
res.status(400).send('Invalid threadId')
}
})
// These are for backwards compatibility
app.get('/room/:projectId/messages', MessageHttpController.getGlobalMessages)
app.post('/room/:projectId/messages', MessageHttpController.sendGlobalMessage)
app.get(
'/project/:projectId/messages',
MessageHttpController.getGlobalMessages
)
app.post(
'/project/:projectId/messages',
MessageHttpController.sendGlobalMessage
)
app.post(
'/project/:projectId/thread/:threadId/messages',
MessageHttpController.sendThreadMessage
)
app.get('/project/:projectId/threads', MessageHttpController.getAllThreads)
app.post(
'/project/:projectId/thread/:threadId/messages/:messageId/edit',
MessageHttpController.editMessage
)
app.delete(
'/project/:projectId/thread/:threadId/messages/:messageId',
MessageHttpController.deleteMessage
)
app.post(
'/project/:projectId/thread/:threadId/resolve',
MessageHttpController.resolveThread
)
app.post(
'/project/:projectId/thread/:threadId/reopen',
MessageHttpController.reopenThread
)
app.delete(
'/project/:projectId/thread/:threadId',
MessageHttpController.deleteThread
)
app.delete('/project/:projectId', MessageHttpController.destroyProject)
app.get('/status', (req, res, next) => res.send('chat is alive'))
}