fix: survey cache invalidation in survey-status cron (#3066)

This commit is contained in:
Anshuman Pandey
2024-08-29 17:57:35 +05:30
committed by GitHub
parent 55c305c569
commit 94e8c1da68

View File

@@ -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.`,
});