feat: adds filter on insights

This commit is contained in:
Piyush Gupta
2025-01-29 11:42:24 +05:30
parent f1d697a83f
commit b6fc104357
2 changed files with 14 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ export const getInsightsBySurveyIdQuestionId = reactCache(
async (
surveyId: string,
questionId: TSurveyQuestionId,
insightResponsesIds: string[],
limit?: number,
offset?: number
): Promise<TSurveyQuestionSummaryOpenText["insights"]> =>
@@ -33,6 +34,11 @@ export const getInsightsBySurveyIdQuestionId = reactCache(
document: {
surveyId,
questionId,
...(insightResponsesIds.length > 0 && {
responseId: {
in: insightResponsesIds,
},
}),
},
},
},

View File

@@ -317,9 +317,11 @@ export const getQuestionSummary = async (
switch (question.type) {
case TSurveyQuestionTypeEnum.OpenText: {
let values: TSurveyQuestionSummaryOpenText["samples"] = [];
const insightResponsesIds: string[] = [];
responses.forEach((response) => {
const answer = response.data[question.id];
if (answer && typeof answer === "string") {
insightResponsesIds.push(response.id);
values.push({
id: response.id,
updatedAt: response.updatedAt,
@@ -329,7 +331,12 @@ export const getQuestionSummary = async (
});
}
});
const insights = await getInsightsBySurveyIdQuestionId(survey.id, question.id, 50);
const insights = await getInsightsBySurveyIdQuestionId(
survey.id,
question.id,
insightResponsesIds,
50
);
summary.push({
type: question.type,