fix: action update cache (#2936)

This commit is contained in:
Anshuman Pandey
2024-07-31 16:48:33 +05:30
committed by GitHub
parent 9d3647f38a
commit b8b7a374a6

View File

@@ -10,6 +10,7 @@ import { ZId } from "@formbricks/types/environment";
import { DatabaseError, ResourceNotFoundError } from "@formbricks/types/errors";
import { cache } from "../cache";
import { ITEMS_PER_PAGE } from "../constants";
import { surveyCache } from "../survey/cache";
import { validateInputs } from "../utils/validate";
import { actionClassCache } from "./cache";
@@ -193,7 +194,14 @@ export const updateActionClass = async (
key: actionClassInput.type === "code" ? actionClassInput.key : undefined,
noCodeConfig: actionClassInput.type === "noCode" ? actionClassInput.noCodeConfig || {} : undefined,
},
select: selectActionClass,
select: {
...selectActionClass,
surveys: {
select: {
surveyId: true,
},
},
},
});
// revalidate cache
@@ -203,6 +211,14 @@ export const updateActionClass = async (
id: result.id,
});
// @ts-expect-error
const surveyIds = result.surveys.map((survey) => survey.surveyId);
for (const surveyId of surveyIds) {
surveyCache.revalidate({
id: surveyId,
});
}
return result;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {