Compare commits

...

5 Commits

Author SHA1 Message Date
pandeymangg
249e42b087 Merge branch 'main' into hmaan-displayId 2025-07-04 14:19:05 +05:30
pandeymangg
9ec4f22b1f Merge remote-tracking branch 'origin/main' into hmaan-displayId 2025-07-03 13:26:52 +05:30
Harsh-deepsingh
ea00dec8e5 fix: rename function as requested 2025-07-02 01:21:34 -06:00
Harsh-deepsingh
70cd751b0e displayId validation as cuid2 if present 2025-06-29 17:50:20 -06:00
Harsh-deepsingh
4308d86bbc fix: add validation for displayId in client response APIs 2025-06-29 17:03:36 -06:00
4 changed files with 35 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { responses } from "@/app/lib/api/response";
import { transformErrorToDetails } from "@/app/lib/api/validator";
import { sendToPipeline } from "@/app/lib/pipelines";
import { getDisplay } from "@/lib/display/service";
import { validateFileUploads } from "@/lib/fileValidation";
import { capturePosthogEnvironmentEvent } from "@/lib/posthogServer";
import { getSurvey } from "@/lib/survey/service";
@@ -97,6 +98,14 @@ export const POST = async (request: Request, context: Context): Promise<Response
return responses.badRequestResponse("Invalid file upload response");
}
// check display
if (responseInputData.displayId) {
const display = await getDisplay(responseInputData.displayId);
if (!display) {
return responses.notFoundResponse("Display", responseInputData.displayId, true);
}
}
let response: TResponse;
try {
const meta: TResponseInput["meta"] = {

View File

@@ -2,6 +2,7 @@ import { checkSurveyValidity } from "@/app/api/v2/client/[environmentId]/respons
import { responses } from "@/app/lib/api/response";
import { transformErrorToDetails } from "@/app/lib/api/validator";
import { sendToPipeline } from "@/app/lib/pipelines";
import { getDisplay } from "@/lib/display/service";
import { capturePosthogEnvironmentEvent } from "@/lib/posthogServer";
import { getSurvey } from "@/lib/survey/service";
import { validateOtherOptionLengthForMultipleChoice } from "@/modules/api/v2/lib/question";
@@ -104,6 +105,14 @@ export const POST = async (request: Request, context: Context): Promise<Response
);
}
// check display
if (responseInputData.displayId) {
const display = await getDisplay(responseInputData.displayId);
if (!display) {
return responses.notFoundResponse("Display", responseInputData.displayId, true);
}
}
let response: TResponse;
try {
const meta: TResponseInputV2["meta"] = {

View File

@@ -62,3 +62,19 @@ export const deleteDisplay = async (displayId: string): Promise<TDisplay> => {
throw error;
}
};
export const getDisplay = reactCache(async (displayId: string): Promise<{ id: string } | null> => {
validateInputs([displayId, ZId]);
try {
const display = await prisma.display.findUnique({
where: { id: displayId },
select: { id: true },
});
return display;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError(error.message);
}
throw error;
}
});

View File

@@ -297,7 +297,7 @@ export const ZResponseInput = z.object({
environmentId: z.string().cuid2(),
surveyId: z.string().cuid2(),
userId: z.string().nullish(),
displayId: z.string().nullish(),
displayId: z.string().cuid2().nullish(),
singleUseId: z.string().nullable().optional(),
finished: z.boolean(),
endingId: z.string().nullish(),