mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-29 11:30:11 -05:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { actionClassCache } from "@/lib/actionClass/cache";
|
|
import { cache } from "@/lib/cache";
|
|
import { validateInputs } from "@/lib/utils/validate";
|
|
import { ActionClass } from "@prisma/client";
|
|
import { cache as reactCache } from "react";
|
|
import { z } from "zod";
|
|
import { prisma } from "@formbricks/database";
|
|
import { DatabaseError } from "@formbricks/types/errors";
|
|
|
|
export const getActionClasses = reactCache(
|
|
async (environmentId: string): Promise<ActionClass[]> =>
|
|
cache(
|
|
async () => {
|
|
validateInputs([environmentId, z.string().cuid2()]);
|
|
|
|
try {
|
|
return await prisma.actionClass.findMany({
|
|
where: {
|
|
environmentId: environmentId,
|
|
},
|
|
orderBy: {
|
|
createdAt: "asc",
|
|
},
|
|
});
|
|
} catch (error) {
|
|
throw new DatabaseError(`Database error when fetching actions for environment ${environmentId}`);
|
|
}
|
|
},
|
|
[`survey-lib-getActionClasses-${environmentId}`],
|
|
{
|
|
tags: [actionClassCache.tag.byEnvironmentId(environmentId)],
|
|
}
|
|
)()
|
|
);
|