fix: surveys management api input types (#2837)

This commit is contained in:
Anshuman Pandey
2024-07-01 17:34:22 +05:30
committed by GitHub
parent ce4578a829
commit 58df9c6edb
2 changed files with 9 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ import { authenticateRequest, handleErrorResponse } from "@/app/api/v1/auth";
import { responses } from "@/app/lib/api/response";
import { transformErrorToDetails } from "@/app/lib/api/validator";
import { deleteSurvey, getSurvey, updateSurvey } from "@formbricks/lib/survey/service";
import { TSurvey, ZSurvey } from "@formbricks/types/surveys";
import { TSurvey, ZSurveyUpdateInput } from "@formbricks/types/surveys";
const fetchAndAuthorizeSurvey = async (authentication: any, surveyId: string): Promise<TSurvey | null> => {
const survey = await getSurvey(surveyId);
@@ -68,7 +68,7 @@ export const PUT = async (
console.error(`Error parsing JSON input: ${error}`);
return responses.badRequestResponse("Malformed JSON input, please check your request body");
}
const inputValidation = ZSurvey.safeParse({
const inputValidation = ZSurveyUpdateInput.safeParse({
...survey,
...surveyUpdate,
});

View File

@@ -524,6 +524,13 @@ export const ZSurvey = z.object({
showLanguageSwitch: z.boolean().nullable(),
});
export const ZSurveyUpdateInput = ZSurvey.omit({ createdAt: true, updatedAt: true }).and(
z.object({
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
);
export const ZSurveyInput = z.object({
name: z.string(),
type: ZSurveyType.optional(),