feat: new module create topic
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { Elysia } from 'elysia'
|
||||
import CommandService from './commands/service'
|
||||
import { listTopicResponseSchema, listTopics, 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('/', () => {
|
||||
return 'Topics'
|
||||
})
|
||||
.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
|
||||
Reference in New Issue
Block a user