[questions][fix] linting issues

pull/457/head
Jeff Sieu 3 years ago
parent fa9b98ec60
commit a20a87b1a7

@ -1,9 +1,9 @@
import { z } from 'zod'; import { z } from 'zod';
import { createRouter } from '../context';
import { createAggregatedQuestionEncounter } from '~/utils/questions/server/aggregate-encounters'; import { createAggregatedQuestionEncounter } from '~/utils/questions/server/aggregate-encounters';
import { createRouter } from '../context';
export const questionsQuestionEncounterRouter = createRouter().query( export const questionsQuestionEncounterRouter = createRouter().query(
'getAggregatedEncounters', 'getAggregatedEncounters',
{ {
@ -14,9 +14,9 @@ export const questionsQuestionEncounterRouter = createRouter().query(
const questionEncountersData = const questionEncountersData =
await ctx.prisma.questionsQuestionEncounter.findMany({ await ctx.prisma.questionsQuestionEncounter.findMany({
include: { include: {
city: true,
company: true, company: true,
country: true, country: true,
city: true,
state: true, state: true,
}, },
where: { where: {

@ -1,22 +1,26 @@
import type { import type {
City, City,
State,
Country,
Company, Company,
Country,
QuestionsQuestion, QuestionsQuestion,
QuestionsQuestionVote, QuestionsQuestionVote,
State,
} from '@prisma/client'; } from '@prisma/client';
import { Vote } 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<{ type AggregatableEncounters = Array<{
company: Company | null;
city: City | null; city: City | null;
company: Company | null;
country: Country | null; country: Country | null;
state: State | null;
role: string; role: string;
seenAt: Date; seenAt: Date;
state: State | null;
}>; }>;
type QuestionWithAggregatableData = QuestionsQuestion & { type QuestionWithAggregatableData = QuestionsQuestion & {
@ -89,12 +93,11 @@ export function createAggregatedQuestionEncounter(
companyCounts[encounter.company!.name] += 1; companyCounts[encounter.company!.name] += 1;
} }
if (encounter.country !== null) { if (encounter.country !== null) {
if (!(encounter.country.name in countryCounts)) { if (!(encounter.country.name in countryCounts)) {
countryCounts[encounter.country.name] = { countryCounts[encounter.country.name] = {
total: 0,
stateInfos: {}, stateInfos: {},
total: 0,
}; };
} }
const countryInfo = countryCounts[encounter.country.name]; const countryInfo = countryCounts[encounter.country.name];
@ -106,27 +109,25 @@ export function createAggregatedQuestionEncounter(
if (encounter.state !== null) { if (encounter.state !== null) {
if (!(encounter.state.name in countryStateInfo)) { if (!(encounter.state.name in countryStateInfo)) {
countryStateInfo[encounter.state.name] = { countryStateInfo[encounter.state.name] = {
total: 0,
cityCounts: {}, cityCounts: {},
total: 0,
}; };
} }
const stateInfo = countryStateInfo[encounter.state.name]; const stateInfo = countryStateInfo[encounter.state.name];
stateInfo.total += 1; stateInfo.total += 1;
const cityCounts = stateInfo.cityCounts; const { cityCounts } = stateInfo;
if (encounter.city !== null) { if (encounter.city !== null) {
if (!(encounter.city.name in cityCounts)) { if (!(encounter.city.name in cityCounts)) {
cityCounts[encounter.city.name] = 0; cityCounts[encounter.city.name] = 0;
} }
cityCounts[encounter.city.name] += 1; cityCounts[encounter.city.name] += 1;
} }
} }
} }
if (!(encounter.role in roleCounts)) { if (!(encounter.role in roleCounts)) {
roleCounts[encounter.role] = 0; roleCounts[encounter.role] = 0;
} }
@ -135,8 +136,8 @@ export function createAggregatedQuestionEncounter(
return { return {
companyCounts, companyCounts,
latestSeenAt,
countryCounts, countryCounts,
latestSeenAt,
roleCounts, roleCounts,
}; };
} }

Loading…
Cancel
Save