Skip to content

Commit

Permalink
feat: 新增 dbm entry,负责 app db 的数据管理;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jul 28, 2021
1 parent 225330f commit f7ddae3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
37 changes: 37 additions & 0 deletions packages/devops-server/src/router/dbm/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as express from 'express'
import { Entry, Ruler } from 'less-api'
import { checkPermission } from '../../api/permission'
import { Globals } from '../../lib/globals'

Expand All @@ -8,6 +9,42 @@ const logger = Globals.logger

export const DbmRouter = express.Router()

/**
* 数据管理入口请求:管理 app db
*/
DbmRouter.post('/entry', async (req, res) => {
const requestId = req['requestId']

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

const accessor = Globals.app_accessor

// 此处无需进行访问策略验证
const entry = new Entry(accessor, new Ruler(accessor))

// parse params
const params = entry.parseParams({ ...req.body, requestId })

// execute query
try {
const data = await entry.execute(params)

return res.send({
code: 0,
data
})
} catch (error) {
return res.send({
code: 2,
error: error
})
}
})

/**
* 获取集合列表
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/devops-server/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Router } from 'express'
import { AdminRouter } from './admin/index'
import { DevOpsEntryRouter } from './entry/admin'
import { DbmEntryRouter } from './entry/dbm'
import { DevOpsEntryRouter } from './entry'
import { DbmRouter } from './dbm'
import { DeployRouter } from './deploy'

export const router = Router()

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

router.use('/dbm', DbmEntryRouter)
router.use('/dbm', DbmRouter)
router.use('/deploy', DeployRouter)

0 comments on commit f7ddae3

Please sign in to comment.