diff --git a/src/app/models/form.server.model.ts b/src/app/models/form.server.model.ts index 4b353f9235..31d5439ad8 100644 --- a/src/app/models/form.server.model.ts +++ b/src/app/models/form.server.model.ts @@ -29,8 +29,8 @@ import { IFormDocument, IFormModel, IFormSchema, - ILogicWithId, IPopulatedForm, + LogicDto, LogicType, Permission, PickDuplicateForm, @@ -690,7 +690,7 @@ const compileFormModel = (db: Mongoose): IFormModel => { this: IFormModel, formId: string, logicId: string, - updatedLogic: ILogicWithId, + updatedLogic: LogicDto, ): Promise { return this.findByIdAndUpdate( formId, diff --git a/src/app/modules/form/admin-form/admin-form.controller.ts b/src/app/modules/form/admin-form/admin-form.controller.ts index 21802dd058..a36a09384d 100644 --- a/src/app/modules/form/admin-form/admin-form.controller.ts +++ b/src/app/modules/form/admin-form/admin-form.controller.ts @@ -16,7 +16,9 @@ import { IForm, IFormDocument, IPopulatedForm, + LogicConditionState, LogicDto, + LogicIfValue, LogicType, ResponseMode, } from '../../../../types' @@ -1806,9 +1808,20 @@ export const handleUpdateLogic = [ .items( Joi.object({ field: Joi.string().required(), - state: Joi.string().required(), - value: Joi.string().required(), - ifValueType: Joi.string(), + state: Joi.string() + .valid(...Object.values(LogicConditionState)) + .required(), + value: Joi.alternatives() + .try( + Joi.number(), + Joi.string(), + Joi.array().items(Joi.string()), + Joi.array().items(Joi.number()), + ) + .required(), + ifValueType: Joi.string() + .valid(...Object.values(LogicIfValue)) + .required(), }).unknown(true), ) .required(), diff --git a/src/types/form_logic.ts b/src/types/form_logic.ts index 516277efda..87d6f4d476 100644 --- a/src/types/form_logic.ts +++ b/src/types/form_logic.ts @@ -1,5 +1,4 @@ -import { Document, LeanDocument } from 'mongoose' -import { ConditionalPick, Primitive } from 'type-fest' +import { Document } from 'mongoose' import { IFieldSchema } from './field/baseField' import { BasicField } from './field/fieldTypes' @@ -40,10 +39,6 @@ export interface ILogic { export interface ILogicSchema extends ILogic, Document {} -export type ILogicWithId = ILogic & { - _id: string -} - export interface IShowFieldsLogic extends ILogic { show: IFieldSchema['_id'][] } @@ -116,4 +111,4 @@ export type LogicCondition = /** * Logic POJO with functions removed */ -export type LogicDto = ConditionalPick, Primitive> +export type LogicDto = ILogic & { _id?: Document['_id'] }