mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-05 11:21:07 -05:00
chore: remove cron jobs and survey scheduling functionality (#6505)
Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user