fix: 修改创建问卷允许空字符串,参数错误抛出异常 (#83)
This commit is contained in:
parent
39e89a4651
commit
6d692de753
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user