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