fix: 修改更新问卷基础信息的接口允许remark字段为空 (#84)

This commit is contained in:
luch 2024-03-27 15:43:18 +08:00 committed by GitHub
parent 6d692de753
commit 24660cb6c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,14 +8,15 @@ import {
UseGuards, UseGuards,
Request, Request,
} from '@nestjs/common'; } from '@nestjs/common';
import { SurveyMetaService } from '../services/surveyMeta.service';
import * as Joi from 'joi'; import * as Joi from 'joi';
import { Authtication } from 'src/guards/authtication';
import moment from 'moment'; import moment from 'moment';
import { getFilter, getOrder } from 'src/utils/surveyUtil'; 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') @Controller('/api/survey')
export class SurveyMetaController { export class SurveyMetaController {
@ -25,11 +26,17 @@ export class SurveyMetaController {
@Post('/updateMeta') @Post('/updateMeta')
@HttpCode(200) @HttpCode(200)
async updateMeta(@Body() reqBody, @Request() req) { async updateMeta(@Body() reqBody, @Request() req) {
const validationResult = await Joi.object({ let validationResult;
remark: Joi.string().allow(null).default(''), try {
validationResult = await Joi.object({
title: Joi.string().required(), title: Joi.string().required(),
remark: Joi.string().allow(null, '').default(''),
surveyId: Joi.string().required(), surveyId: Joi.string().required(),
}).validateAsync(reqBody, { allowUnknown: true }); }).validateAsync(reqBody, { allowUnknown: true });
} catch (error) {
throw new HttpException('参数错误', EXCEPTION_CODE.PARAMETER_ERROR);
}
const username = req.user.username; const username = req.user.username;
const surveyId = validationResult.surveyId; const surveyId = validationResult.surveyId;
const survey = await this.surveyMetaService.checkSurveyAccess({ const survey = await this.surveyMetaService.checkSurveyAccess({