diff --git a/server/src/modules/survey/controllers/surveyMeta.controller.ts b/server/src/modules/survey/controllers/surveyMeta.controller.ts index c1a7b8e5..f3e9d822 100644 --- a/server/src/modules/survey/controllers/surveyMeta.controller.ts +++ b/server/src/modules/survey/controllers/surveyMeta.controller.ts @@ -8,14 +8,15 @@ import { UseGuards, Request, } from '@nestjs/common'; - -import { SurveyMetaService } from '../services/surveyMeta.service'; - import * as Joi from 'joi'; -import { Authtication } from 'src/guards/authtication'; import moment from 'moment'; import { getFilter, getOrder } from 'src/utils/surveyUtil'; +import { HttpException } from 'src/exceptions/httpException'; +import { EXCEPTION_CODE } from 'src/enums/exceptionCode'; +import { Authtication } from 'src/guards/authtication'; + +import { SurveyMetaService } from '../services/surveyMeta.service'; @Controller('/api/survey') export class SurveyMetaController { @@ -25,11 +26,17 @@ export class SurveyMetaController { @Post('/updateMeta') @HttpCode(200) async updateMeta(@Body() reqBody, @Request() req) { - const validationResult = await Joi.object({ - remark: Joi.string().allow(null).default(''), - title: Joi.string().required(), - surveyId: Joi.string().required(), - }).validateAsync(reqBody, { allowUnknown: true }); + let validationResult; + try { + validationResult = await Joi.object({ + title: Joi.string().required(), + remark: Joi.string().allow(null, '').default(''), + surveyId: Joi.string().required(), + }).validateAsync(reqBody, { allowUnknown: true }); + } catch (error) { + throw new HttpException('参数错误', EXCEPTION_CODE.PARAMETER_ERROR); + } + const username = req.user.username; const surveyId = validationResult.surveyId; const survey = await this.surveyMetaService.checkSurveyAccess({