mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
fix: wrap all async controller with error handler
* add validations to newCommand
This commit is contained in:
1 parent
1af85651b8
commit
c2dac8d385
13 files changed
+120
-120
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { body } from 'express-validator'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkCommand = () => body('command').isString().notEmpty().trim()
|
||||
const checkPwd = () => body('pwd').isString().notEmpty().trim()
|
||||
const checkOutput = () => body('output').trim().optional()
|
||||
const checkError = () => body('error').trim().optional()
|
||||
const checkParams = () => body('params').isObject().optional()
|
||||
|
||||
export const newCommandValidator = [
|
||||
checkCommand(),
|
||||
checkPwd(),
|
||||
checkOutput(),
|
||||
checkError(),
|
||||
checkParams(),
|
||||
noError,
|
||||
]
|
||||
@@ -3,9 +3,7 @@ import { checkQuestId } from './questValidator.js'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkSessionStatus = () =>
|
||||
check('status')
|
||||
.isString()
|
||||
.custom((value) => ['active', 'inactive', 'finished'].includes(value))
|
||||
check('status').isString().isIn(['active', 'inactive', 'finished'])
|
||||
|
||||
export const checkSessionId = () =>
|
||||
check('sessionId').notEmpty().isString().isMongoId()
|
||||
|
||||
Reference in new issue
Block a user