[questions][feat] update frontend to use companyId

pull/351/head
Jeff Sieu 3 years ago
parent b5d5a3d9ed
commit ee85a8e38f

@ -84,9 +84,8 @@ export default function ContributeQuestionForm({
name="company" name="company"
render={({ field }) => ( render={({ field }) => (
<CompaniesTypeahead <CompaniesTypeahead
onSelect={({ label }) => { onSelect={({ id }) => {
// TODO: To change from using company name to company id (i.e., value) field.onChange(id);
field.onChange(label);
}} }}
/> />
)} )}

@ -65,7 +65,7 @@ export default function QuestionsHomePage() {
[ [
'questions.questions.getQuestionsByFilter', 'questions.questions.getQuestionsByFilter',
{ {
companies: selectedCompanies, companyNames: selectedCompanies,
endDate: today, endDate: today,
locations: selectedLocations, locations: selectedLocations,
questionTypes: selectedQuestionTypes, questionTypes: selectedQuestionTypes,
@ -252,7 +252,7 @@ export default function QuestionsHomePage() {
<ContributeQuestionCard <ContributeQuestionCard
onSubmit={(data) => { onSubmit={(data) => {
createQuestion({ createQuestion({
company: data.company, companyId: data.company,
content: data.questionContent, content: data.questionContent,
location: data.location, location: data.location,
questionType: data.questionType, questionType: data.questionType,

@ -9,7 +9,7 @@ import type { Question } from '~/types/questions';
export const questionsQuestionRouter = createProtectedRouter() export const questionsQuestionRouter = createProtectedRouter()
.query('getQuestionsByFilter', { .query('getQuestionsByFilter', {
input: z.object({ input: z.object({
companyIds: z.string().array(), companyNames: z.string().array(),
endDate: z.date(), endDate: z.date(),
locations: z.string().array(), locations: z.string().array(),
questionTypes: z.nativeEnum(QuestionsQuestionType).array(), questionTypes: z.nativeEnum(QuestionsQuestionType).array(),
@ -51,35 +51,36 @@ export const questionsQuestionRouter = createProtectedRouter()
}, },
} }
: {}), : {}),
encounters : { encounters: {
some: { some: {
...(input.companies.length > 0 ...(input.companyNames.length > 0
? { ? {
company : { company: {
in : input.companies name: {
} in: input.companyNames,
},
},
} }
: {}), : {}),
...(input.locations.length > 0 ...(input.locations.length > 0
? { ? {
location: { location: {
in: input.locations in: input.locations,
}, },
} }
: {}), : {}),
...(input.roles.length > 0 ...(input.roles.length > 0
? { ? {
role : { role: {
in: input.roles in: input.roles,
} },
} }
: {}), : {}),
} },
} },
}, },
}); });
return questionsData return questionsData.map((data) => {
.map((data) => {
const votes: number = data.votes.reduce( const votes: number = data.votes.reduce(
(previousValue: number, currentValue) => { (previousValue: number, currentValue) => {
let result: number = previousValue; let result: number = previousValue;
@ -205,11 +206,19 @@ export const questionsQuestionRouter = createProtectedRouter()
encounters: { encounters: {
create: [ create: [
{ {
company: input.companyId, company: {
connect: {
id: input.companyId,
},
},
location: input.location, location: input.location,
role: input.role, role: input.role,
seenAt: input.seenAt, seenAt: input.seenAt,
userId, user: {
connect: {
id: userId,
},
},
}, },
], ],
}, },
@ -245,7 +254,6 @@ export const questionsQuestionRouter = createProtectedRouter()
const { content, questionType } = input; const { content, questionType } = input;
return await ctx.prisma.questionsQuestion.update({ return await ctx.prisma.questionsQuestion.update({
data: { data: {
content, content,
questionType, questionType,

Loading…
Cancel
Save