[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 { 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: {

@ -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,
};
}

Loading…
Cancel
Save