Skip to content

Commit

Permalink
Clean up summary stats endpoint and handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Nov 18, 2024
1 parent 16b1add commit b724cc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/app/utils/api/apiHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ export const getP1SummaryStats: (
*/
export const getP1TotPopSummaryStats: (
mapDocument: DocumentObject | null
) => Promise<SummaryStatsResult<P1TotPopSummaryStats[]>> = async mapDocument => {
) => Promise<SummaryStatsResult<P1TotPopSummaryStats>> = async mapDocument => {
if (mapDocument) {
return await axios
.get<SummaryStatsResult<P1TotPopSummaryStats[]>>(`${process.env.NEXT_PUBLIC_API_URL}/api/districtrmap/summary_stats/P1/${mapDocument.parent_layer}`)
.get<SummaryStatsResult<P1TotPopSummaryStats>>(`${process.env.NEXT_PUBLIC_API_URL}/api/districtrmap/summary_stats/P1/${mapDocument.parent_layer}`)
.then(res => res.data)
} else {
throw new Error('No document provided');
Expand Down
8 changes: 4 additions & 4 deletions app/src/app/utils/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const getQueriesResultsSubs = (_useMapStore: typeof useMapStore) => {
}
});
fetchTotPop.subscribe(response => {
if (response?.data?.results?.length) {
useMapStore.getState().setSummaryStat('totpop', { data: response.data.results[0]});
if (response?.data?.results) {
useMapStore.getState().setSummaryStat('totpop', { data: response.data.results});
} else {
useMapStore.getState().setSummaryStat('totpop', undefined)
}
Expand Down Expand Up @@ -126,9 +126,9 @@ fetchAssignments.subscribe(assignments => {
}
});

export const fetchTotPop = new QueryObserver<SummaryStatsResult<P1TotPopSummaryStats[]> | null>(queryClient, {
export const fetchTotPop = new QueryObserver<SummaryStatsResult<P1TotPopSummaryStats> | null>(queryClient, {
queryKey: ['gerrydb_tot_pop'],
queryFn: getNullableParamQuery<MapStore['mapDocument'], SummaryStatsResult<P1TotPopSummaryStats[]>>(getP1TotPopSummaryStats),
queryFn: getNullableParamQuery<MapStore['mapDocument'], SummaryStatsResult<P1TotPopSummaryStats>>(getP1TotPopSummaryStats),
});

export const updateTotPop = (mapDocument: DocumentObject | null) => {
Expand Down
4 changes: 2 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ async def get_gerrydb_summary_stat(
bindparam(key="gerrydb_table", type_=String),
)
try:
(row,) = session.execute(stmt, {"gerrydb_table": gerrydb_table}).one()
results = session.execute(stmt, {"gerrydb_table": gerrydb_table}).fetchone()
return {
"summary_stat": _summary_stat.value,
"results": [SummaryStatsModel.from_orm(row)],
"results": SummaryStatsModel.from_orm(results),
}
except ProgrammingError as e:
logger.error(e)
Expand Down

0 comments on commit b724cc8

Please sign in to comment.