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

This commit is contained in:
luch 2024-03-27 14:45:25 +08:00 committed by sudoooooo
parent 5c99bd759e
commit 15a41f1ba7

View File

@ -50,21 +50,26 @@ export class SurveyController {
@Request()
req,
) {
const validationResult = await Joi.object({
remark: Joi.string().required(),
title: Joi.string().required(),
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;