Skip to content

Commit

Permalink
fix(api): Return the correct total count for WidgetChartData
Browse files Browse the repository at this point in the history
  • Loading branch information
alepefe-vizz committed Nov 6, 2024
1 parent ebc37d5 commit b508da4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/src/infrastructure/postgres-survey-answers.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ export class PostgresSurveyAnswerRepository
): Promise<void> {
const totalsSql = `SELECT answer as "key", count(answer)::integer as "count", SUM(COUNT(answer)) OVER ()::integer AS total
FROM ${this.answersTable} ${this.sqlAdapter.appendExpressionToFilterClause(filterClause, `question_indicator = '${widget.indicator}'`)} GROUP BY answer ORDER BY answer`;
const totalsResult: { key: string; count: number }[] =
const totalsResult: { key: string; count: number; total: number }[] =
await this.dataSource.query(totalsSql);

const arr: WidgetChartData = [];
for (let rowIdx = 0; rowIdx < totalsResult.length; rowIdx++) {
const res = totalsResult[rowIdx];
arr.push({ label: res.key, value: res.count, total: res.count });
arr.push({ label: res.key, value: res.count, total: res.total });
}

widget.data.chart = arr;
Expand Down
6 changes: 3 additions & 3 deletions api/test/e2e/widgets/base-widgets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ describe('Base Widgets', () => {
{
label: 'N/A',
value: 1,
total: 1,
total: 5,
},
{
label: 'No',
value: 2,
total: 2,
total: 5,
},
{
label: 'Yes',
value: 2,
total: 2,
total: 5,
},
],
},
Expand Down

0 comments on commit b508da4

Please sign in to comment.