chore: remove cron jobs and survey scheduling functionality (#6505)

Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
This commit is contained in:
Piyush Gupta
2025-09-11 12:27:11 +05:30
committed by GitHub
parent 0188aad97b
commit dd394f1d2c
110 changed files with 414 additions and 1096 deletions
@@ -148,8 +148,6 @@ export const mockSurvey: TSurvey = {
recontactDays: null,
displayLimit: null,
autoClose: null,
runOnDate: null,
closeOnDate: null,
delay: 0,
displayPercentage: null,
autoComplete: null,
@@ -143,7 +143,6 @@ const mockSurvey = {
segment: null,
recontactDays: null,
autoComplete: null,
closeOnDate: null,
createdAt: new Date(),
updatedAt: new Date(),
displayOption: "displayOnce",
-35
View File
@@ -1,35 +0,0 @@
import { responses } from "@/app/lib/api/response";
import { CRON_SECRET } from "@/lib/constants";
import { env } from "@/lib/env";
import { captureTelemetry } from "@/lib/telemetry";
import packageJson from "@/package.json";
import { headers } from "next/headers";
import { prisma } from "@formbricks/database";
export const POST = async () => {
const headersList = await headers();
const apiKey = headersList.get("x-api-key");
if (!apiKey || apiKey !== CRON_SECRET) {
return responses.notAuthenticatedResponse();
}
if (env.TELEMETRY_DISABLED === "1") {
return responses.successResponse({}, true);
}
const [surveyCount, responseCount, userCount] = await Promise.all([
prisma.survey.count(),
prisma.response.count(),
prisma.user.count(),
]);
captureTelemetry("ping", {
version: packageJson.version,
surveyCount,
responseCount,
userCount,
});
return responses.successResponse({}, true);
};
@@ -1,71 +0,0 @@
import { responses } from "@/app/lib/api/response";
import { CRON_SECRET } from "@/lib/constants";
import { headers } from "next/headers";
import { prisma } from "@formbricks/database";
export const POST = async () => {
const headersList = await headers();
const apiKey = headersList.get("x-api-key");
if (!apiKey || apiKey !== CRON_SECRET) {
return responses.notAuthenticatedResponse();
}
// close surveys that are in progress and have a closeOnDate in the past
const surveysToClose = await prisma.survey.findMany({
where: {
status: "inProgress",
closeOnDate: {
lte: new Date(),
},
},
select: {
id: true,
environmentId: true,
},
});
if (surveysToClose.length) {
await prisma.survey.updateMany({
where: {
id: {
in: surveysToClose.map((survey) => survey.id),
},
},
data: {
status: "completed",
},
});
}
// run surveys that are scheduled and have a runOnDate in the past
const scheduledSurveys = await prisma.survey.findMany({
where: {
status: "scheduled",
runOnDate: {
lte: new Date(),
},
},
select: {
id: true,
environmentId: true,
},
});
if (scheduledSurveys.length) {
await prisma.survey.updateMany({
where: {
id: {
in: scheduledSurveys.map((survey) => survey.id),
},
},
data: {
status: "inProgress",
},
});
}
return responses.successResponse({
message: `Updated ${surveysToClose.length} surveys to completed and ${scheduledSurveys.length} surveys to inProgress.`,
});
};
@@ -80,7 +80,6 @@ const baseSurvey: TSurvey = {
displayOption: "displayOnce",
recontactDays: null,
autoClose: null,
closeOnDate: null,
delay: 0,
displayPercentage: null,
autoComplete: null,
@@ -100,7 +99,6 @@ const baseSurvey: TSurvey = {
isSingleResponsePerEmailEnabled: false,
isVerifyEmailEnabled: false,
projectOverwrites: null,
runOnDate: null,
showLanguageSwitch: false,
isBackButtonHidden: false,
followUps: [],
@@ -51,14 +51,12 @@ const baseSurvey: TSurvey = {
isSingleResponsePerEmailEnabled: false,
isVerifyEmailEnabled: false,
projectOverwrites: null,
runOnDate: null,
showLanguageSwitch: false,
isBackButtonHidden: false,
followUps: [],
recaptcha: { enabled: false, threshold: 0.5 },
displayOption: "displayOnce",
autoClose: null,
closeOnDate: null,
delay: 0,
displayPercentage: null,
autoComplete: null,
@@ -107,13 +107,11 @@ const mockSurveys: TSurvey[] = [
isSingleResponsePerEmailEnabled: false,
isVerifyEmailEnabled: false,
projectOverwrites: null,
runOnDate: null,
showLanguageSwitch: false,
questions: [],
displayOption: "displayOnce",
recontactDays: null,
autoClose: null,
closeOnDate: null,
delay: 0,
displayPercentage: null,
autoComplete: null,
@@ -60,7 +60,6 @@ const mockSurvey: TSurvey = {
displayOption: "displayOnce",
recontactDays: null,
autoClose: null,
closeOnDate: null,
delay: 0,
displayPercentage: null,
autoComplete: null,
@@ -83,7 +82,6 @@ const mockSurvey: TSurvey = {
isSingleResponsePerEmailEnabled: false,
isVerifyEmailEnabled: false,
projectOverwrites: null,
runOnDate: null,
showLanguageSwitch: false,
};