From a20a87b1a73733f8d8ad671f0c4cf546192e3039 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Mon, 31 Oct 2022 02:32:07 +0800 Subject: [PATCH] [questions][fix] linting issues --- .../questions-question-encounter-router.ts | 6 ++--- .../questions/server/aggregate-encounters.ts | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/portal/src/server/router/questions/questions-question-encounter-router.ts b/apps/portal/src/server/router/questions/questions-question-encounter-router.ts index 45c07620..6f00e6b1 100644 --- a/apps/portal/src/server/router/questions/questions-question-encounter-router.ts +++ b/apps/portal/src/server/router/questions/questions-question-encounter-router.ts @@ -1,9 +1,9 @@ import { z } from 'zod'; -import { createRouter } from '../context'; - import { createAggregatedQuestionEncounter } from '~/utils/questions/server/aggregate-encounters'; +import { createRouter } from '../context'; + export const questionsQuestionEncounterRouter = createRouter().query( 'getAggregatedEncounters', { @@ -14,9 +14,9 @@ export const questionsQuestionEncounterRouter = createRouter().query( const questionEncountersData = await ctx.prisma.questionsQuestionEncounter.findMany({ include: { + city: true, company: true, country: true, - city: true, state: true, }, where: { diff --git a/apps/portal/src/utils/questions/server/aggregate-encounters.ts b/apps/portal/src/utils/questions/server/aggregate-encounters.ts index cc698d72..189bcd1a 100644 --- a/apps/portal/src/utils/questions/server/aggregate-encounters.ts +++ b/apps/portal/src/utils/questions/server/aggregate-encounters.ts @@ -1,22 +1,26 @@ import type { City, - State, - Country, Company, + Country, QuestionsQuestion, QuestionsQuestionVote, + State, } from '@prisma/client'; import { Vote } from '@prisma/client'; -import type { AggregatedQuestionEncounter, Question, CountryInfo} from '~/types/questions'; +import type { + AggregatedQuestionEncounter, + CountryInfo, + Question, +} from '~/types/questions'; type AggregatableEncounters = Array<{ - company: Company | null; city: City | null; + company: Company | null; country: Country | null; - state: State | null; role: string; seenAt: Date; + state: State | null; }>; type QuestionWithAggregatableData = QuestionsQuestion & { @@ -89,12 +93,11 @@ export function createAggregatedQuestionEncounter( companyCounts[encounter.company!.name] += 1; } - if (encounter.country !== null) { if (!(encounter.country.name in countryCounts)) { countryCounts[encounter.country.name] = { - total: 0, stateInfos: {}, + total: 0, }; } const countryInfo = countryCounts[encounter.country.name]; @@ -106,27 +109,25 @@ export function createAggregatedQuestionEncounter( if (encounter.state !== null) { if (!(encounter.state.name in countryStateInfo)) { countryStateInfo[encounter.state.name] = { - total: 0, cityCounts: {}, + total: 0, }; } const stateInfo = countryStateInfo[encounter.state.name]; stateInfo.total += 1; - const cityCounts = stateInfo.cityCounts; + const { cityCounts } = stateInfo; if (encounter.city !== null) { if (!(encounter.city.name in cityCounts)) { cityCounts[encounter.city.name] = 0; } cityCounts[encounter.city.name] += 1; - } } } - if (!(encounter.role in roleCounts)) { roleCounts[encounter.role] = 0; } @@ -135,8 +136,8 @@ export function createAggregatedQuestionEncounter( return { companyCounts, - latestSeenAt, countryCounts, + latestSeenAt, roleCounts, }; }