Files
formbricks/apps/web/modules/ee/contacts/lib/surveys.ts
T
2025-11-18 05:37:23 +00:00

33 lines
821 B
TypeScript

import "server-only";
import { Prisma } from "@prisma/client";
import { cache as reactCache } from "react";
import { prisma } from "@formbricks/database";
import { DatabaseError } from "@formbricks/types/errors";
export interface PublishedLinkSurvey {
id: string;
name: string;
}
export const getPublishedLinkSurveys = reactCache(
async (environmentId: string): Promise<PublishedLinkSurvey[]> => {
try {
const surveys = await prisma.survey.findMany({
where: { environmentId, status: "inProgress", type: "link" },
select: {
id: true,
name: true,
},
});
return surveys;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError(error.message);
}
throw error;
}
}
);