fix: display count not getting decremented

This commit is contained in:
Dhruwang
2023-10-04 16:26:20 +05:30
parent f01f55521a
commit 7ae1599c03
3 changed files with 6 additions and 14 deletions

View File

@@ -30,7 +30,9 @@ export default async function Page({ params }) {
getEnvironment(params.environmentId),
]);
const isSingleUseSurvey = survey.singleUse?.enabled ?? false;
const singleUseIds = generateSingleUseIds(survey.singleUse?.isEncrypted ?? false);
const singleUseIds = survey.singleUse?.enabled
? generateSingleUseIds(survey.singleUse?.isEncrypted ?? false)
: undefined;
if (!environment) {
throw new Error("Environment not found");
}

View File

@@ -374,7 +374,7 @@ export const deleteResponse = async (responseId: string): Promise<TResponse> =>
person: responsePrisma.person ? transformPrismaPerson(responsePrisma.person) : null,
tags: responsePrisma.tags.map((tagPrisma: { tag: TTag }) => tagPrisma.tag),
};
deleteDisplayByResponseId(responseId);
deleteDisplayByResponseId(responseId, response.surveyId);
return response;
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {

View File

@@ -41,14 +41,6 @@ const selectDisplay = {
},
status: true,
};
export const getDisplayCount = async (surveyId) => {
const numDisplays = await prisma.display.findMany({
where: {
surveyId,
},
});
return numDisplays;
};
export const updateDisplay = async (
displayId: string,
@@ -214,7 +206,7 @@ export const getDisplaysOfPerson = cache(
}
);
export const deleteDisplayByResponseId = async (responseId: string): Promise<void> => {
export const deleteDisplayByResponseId = async (responseId: string, surveyId: string): Promise<void> => {
validateInputs([responseId, ZId]);
try {
await prisma.display.delete({
@@ -222,13 +214,11 @@ export const deleteDisplayByResponseId = async (responseId: string): Promise<voi
responseId,
},
});
console.log("deleted");
revalidateTag(getDisplaysCacheTag(surveyId));
} catch (error) {
console.log(error);
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError("Database operation failed");
}
throw error;
}
};