diff --git a/apps/web/app/api/cron/survey-status/route.ts b/apps/web/app/api/cron/survey-status/route.ts index 678b0066f9..a16511856b 100644 --- a/apps/web/app/api/cron/survey-status/route.ts +++ b/apps/web/app/api/cron/survey-status/route.ts @@ -2,6 +2,7 @@ import { responses } from "@/app/lib/api/response"; import { headers } from "next/headers"; import { prisma } from "@formbricks/database"; import { CRON_SECRET } from "@formbricks/lib/constants"; +import { surveyCache } from "@formbricks/lib/survey/cache"; export const POST = async () => { const headersList = headers(); @@ -21,6 +22,7 @@ export const POST = async () => { }, select: { id: true, + environmentId: true, }, }); @@ -47,6 +49,7 @@ export const POST = async () => { }, select: { id: true, + environmentId: true, }, }); @@ -63,6 +66,15 @@ export const POST = async () => { }); } + const updatedSurveys = [...surveysToClose, ...scheduledSurveys]; + + for (const survey of updatedSurveys) { + surveyCache.revalidate({ + id: survey.id, + environmentId: survey.environmentId, + }); + } + return responses.successResponse({ message: `Updated ${surveysToClose.length} surveys to completed and ${scheduledSurveys.length} surveys to inProgress.`, });