Skip to content

Commit

Permalink
feat: 增加dbm 获取集合列表;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jun 21, 2021
1 parent ea8e4a1 commit 20693c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
19 changes: 19 additions & 0 deletions http/dbm.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

@token={{login.response.body.$.data.access_token}}

### 管理员登陆
# @name login

POST {{base_url}}/admin/login HTTP/1.1
Content-Type: application/json

{
"username": "less",
"password": "less123"
}

### 获取集合列表

GET {{base_url}}/admin/collections
Content-Type: application/json
Authorization: Bearer {{token}}
25 changes: 25 additions & 0 deletions src/router/dbm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as express from 'express'
import { checkPermission } from '../../lib/api/permission'
import { accessor } from '../../lib/db'
import { getLogger } from '../../lib/logger'


export const DbmRouter = express.Router()
const logger = getLogger('admin:api')


DbmRouter.get('/collections', async (req, res) => {
const requestId = req['requestId']
logger.info(`[${requestId}] get /collections`)

// 权限验证
const code = await checkPermission(req['auth']?.uid, 'collections.get')
if (code) {
return res.status(code).send()
}

const colls = await accessor.db.collections()
const names = colls.map(coll => coll.collectionName)

return res.send(names)
})
3 changes: 2 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { AdminEntryRouter } from './entry/admin'
import { AppEntryRouter } from './entry/app'
import { FileRouter } from './file/index'
import { FunctionRouter } from './function/index'

import { DbmRouter } from './dbm'
export const router = Router()

router.use('/admin', AdminEntryRouter)
router.use('/admin', AdminRouter)
router.use('/admin', DbmRouter)

router.use('/app', AppEntryRouter)

Expand Down

0 comments on commit 20693c7

Please sign in to comment.