mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 03:21:20 -05:00
fix: display count change on date filter (#2208)
This commit is contained in:
@@ -8,6 +8,7 @@ import { ZOptionalNumber } from "@formbricks/types/common";
|
||||
import {
|
||||
TDisplay,
|
||||
TDisplayCreateInput,
|
||||
TDisplayFilters,
|
||||
TDisplayLegacyCreateInput,
|
||||
TDisplayLegacyUpdateInput,
|
||||
TDisplayUpdateInput,
|
||||
@@ -343,7 +344,10 @@ export const deleteDisplayByResponseId = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const getDisplayCountBySurveyId = async (surveyId: string): Promise<number> =>
|
||||
export const getDisplayCountBySurveyId = async (
|
||||
surveyId: string,
|
||||
filters?: TDisplayFilters
|
||||
): Promise<number> =>
|
||||
unstable_cache(
|
||||
async () => {
|
||||
validateInputs([surveyId, ZId]);
|
||||
@@ -352,6 +356,13 @@ export const getDisplayCountBySurveyId = async (surveyId: string): Promise<numbe
|
||||
const displayCount = await prisma.display.count({
|
||||
where: {
|
||||
surveyId: surveyId,
|
||||
...(filters &&
|
||||
filters.createdAt && {
|
||||
createdAt: {
|
||||
gte: filters.createdAt.min,
|
||||
lte: filters.createdAt.max,
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
return displayCount;
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
import { TTag } from "@formbricks/types/tags";
|
||||
|
||||
import { ITEMS_PER_PAGE, SERVICES_REVALIDATION_INTERVAL, WEBAPP_URL } from "../constants";
|
||||
import { deleteDisplayByResponseId } from "../display/service";
|
||||
import { deleteDisplayByResponseId, getDisplayCountBySurveyId } from "../display/service";
|
||||
import { createPerson, getPerson, getPersonByUserId, transformPrismaPerson } from "../person/service";
|
||||
import {
|
||||
buildWhereClause,
|
||||
@@ -534,7 +534,7 @@ export const getSurveySummary = (
|
||||
}
|
||||
|
||||
const batchSize = 3000;
|
||||
const responseCount = await getResponseCountBySurveyId(surveyId);
|
||||
const responseCount = await getResponseCountBySurveyId(surveyId, filterCriteria);
|
||||
const pages = Math.ceil(responseCount / batchSize);
|
||||
|
||||
const responsesArray = await Promise.all(
|
||||
@@ -544,10 +544,8 @@ export const getSurveySummary = (
|
||||
);
|
||||
const responses = responsesArray.flat();
|
||||
|
||||
const displayCount = await prisma.display.count({
|
||||
where: {
|
||||
surveyId,
|
||||
},
|
||||
const displayCount = await getDisplayCountBySurveyId(surveyId, {
|
||||
createdAt: filterCriteria?.createdAt,
|
||||
});
|
||||
|
||||
const meta = getSurveySummaryMeta(responses, displayCount);
|
||||
@@ -583,7 +581,7 @@ export const getResponseDownloadUrl = async (
|
||||
|
||||
const accessType = "private";
|
||||
const batchSize = 3000;
|
||||
const responseCount = await getResponseCountBySurveyId(surveyId);
|
||||
const responseCount = await getResponseCountBySurveyId(surveyId, filterCriteria);
|
||||
const pages = Math.ceil(responseCount / batchSize);
|
||||
|
||||
const responsesArray = await Promise.all(
|
||||
@@ -826,7 +824,7 @@ export const getResponseCountBySurveyId = async (
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
[`getResponseCountBySurveyId-${surveyId}`],
|
||||
[`getResponseCountBySurveyId-${surveyId}-${JSON.stringify(filterCriteria)}`],
|
||||
{
|
||||
tags: [responseCache.tag.bySurveyId(surveyId)],
|
||||
revalidate: SERVICES_REVALIDATION_INTERVAL,
|
||||
|
||||
@@ -49,3 +49,14 @@ export const ZDisplaysWithSurveyName = ZDisplay.extend({
|
||||
});
|
||||
|
||||
export type TDisplaysWithSurveyName = z.infer<typeof ZDisplaysWithSurveyName>;
|
||||
|
||||
export const ZDisplayFilters = z.object({
|
||||
createdAt: z
|
||||
.object({
|
||||
min: z.date().optional(),
|
||||
max: z.date().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type TDisplayFilters = z.infer<typeof ZDisplayFilters>;
|
||||
|
||||
Reference in New Issue
Block a user