fix: 修改创建问卷允许空字符串,参数错误抛出异常 (#83)

This commit is contained in:
luch 2024-03-27 14:45:25 +08:00 committed by GitHub
parent 39e89a4651
commit 6d692de753
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,21 +50,26 @@ export class SurveyController {
@Request()
req,
) {
const validationResult = await Joi.object({
title: Joi.string().required(),
remark: Joi.string().allow(null).default(''),
surveyType: Joi.string().when('createMethod', {
is: 'copy',
then: Joi.allow(null),
otherwise: Joi.required(),
}),
createMethod: Joi.string().allow(null).default('basic'),
createFrom: Joi.string().when('createMethod', {
is: 'copy',
then: Joi.required(),
otherwise: Joi.allow(null),
}),
}).validateAsync(reqBody);
let validationResult;
try {
validationResult = await Joi.object({
title: Joi.string().required(),
remark: Joi.string().allow(null, '').default(''),
surveyType: Joi.string().when('createMethod', {
is: 'copy',
then: Joi.allow(null),
otherwise: Joi.required(),
}),
createMethod: Joi.string().allow(null).default('basic'),
createFrom: Joi.string().when('createMethod', {
is: 'copy',
then: Joi.required(),
otherwise: Joi.allow(null),
}),
}).validateAsync(reqBody);
} catch (error) {
throw new HttpException('参数错误', EXCEPTION_CODE.PARAMETER_ERROR);
}
const { title, remark, createMethod, createFrom } = validationResult;