75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import { Elysia } from 'elysia'
|
|
import CommandService from './commands/service'
|
|
import { listTopicResponseSchema, listTopics, patchTopic, postDeleteTopic, postDeleteTopicResponseSchema } from './schema'
|
|
import QueryService from './queries/service'
|
|
import { basicAuthMacro } from '../../middlewares/basicAuth'
|
|
|
|
export const router = new Elysia({
|
|
name: 'modules.topics',
|
|
detail: { tags: ['Topics'] },
|
|
prefix: '/topics/v1',
|
|
})
|
|
.use(basicAuthMacro)
|
|
.get('/state-reply', async ({ query, set }) => {
|
|
const result = await QueryService.getStateReply(query)
|
|
if (result.status != 200) {
|
|
set.status = result.status
|
|
return result
|
|
}
|
|
return result
|
|
}, {
|
|
query: listTopics,
|
|
response: listTopicResponseSchema,
|
|
verifyBasicAuth: true,
|
|
})
|
|
.get('/commands', async ({ query, set }) => {
|
|
const result = await QueryService.getCommands(query)
|
|
if (result.status != 200) {
|
|
set.status = result.status
|
|
return result
|
|
}
|
|
return result
|
|
}, {
|
|
query: listTopics,
|
|
response: listTopicResponseSchema,
|
|
verifyBasicAuth: true,
|
|
})
|
|
.post('/', async ({ body, set }) => {
|
|
const result = await CommandService.postTopic(body)
|
|
if (result.status != 200) {
|
|
set.status = result.status
|
|
return result
|
|
}
|
|
return result
|
|
}, {
|
|
body: postDeleteTopic,
|
|
response: postDeleteTopicResponseSchema,
|
|
verifyBasicAuth: true,
|
|
})
|
|
.patch('/', async ({ body, set }) => {
|
|
const result = await CommandService.patchTopic(body)
|
|
if (result.status != 200) {
|
|
set.status = result.status
|
|
return result
|
|
}
|
|
return result
|
|
}, {
|
|
verifyBasicAuth: true,
|
|
body: patchTopic,
|
|
response: postDeleteTopicResponseSchema,
|
|
})
|
|
.delete('/', async ({ body, set }) => {
|
|
const result = await CommandService.delTopic(body)
|
|
if (result.status != 200) {
|
|
set.status = result.status
|
|
return result
|
|
}
|
|
return result
|
|
}, {
|
|
body: postDeleteTopic,
|
|
response: postDeleteTopicResponseSchema,
|
|
verifyBasicAuth: true,
|
|
})
|
|
|
|
export default router
|