mirror of
https://github.com/formbricks/formbricks.git
synced 2026-03-01 12:00:02 -06:00
fix: survey cache invalidation in survey-status cron (#3066)
This commit is contained in:
@@ -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.`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user