[questions][feat] update crud to support new fields

pull/457/head
hpkoh 3 years ago
parent b41c08b543
commit 46f69414a1

@ -1,6 +1,7 @@
import { z } from 'zod';
import { TRPCError } from '@trpc/server';
import { JobTitleLabels } from '~/components/shared/JobTitles';
import { createProtectedRouter } from '../context';
@ -10,9 +11,11 @@ export const questionsQuestionEncounterUserRouter = createProtectedRouter()
.mutation('create', {
input: z.object({
companyId: z.string(),
location: z.string(),
cityId: z.string().nullish(),
countryId: z.string(),
stateId: z.string().nullish(),
questionId: z.string(),
role: z.string(),
role: z.nativeEnum(JobTitleLabels),
seenAt: z.date(),
}),
async resolve({ ctx, input }) {

@ -99,7 +99,33 @@ export const questionsQuestionRouter = createRouter()
},
}
: {}),
// TODO: Add filter for cityIds, countryIds, stateIds
...(input.cityIds.length > 0
? {
city: {
id: {
in: input.cityIds,
},
},
}
: {}),
...(input.countryIds.length > 0
? {
country: {
id: {
in: input.countryIds,
},
},
}
: {}),
...(input.stateIds.length > 0
? {
state: {
id: {
in: input.stateIds,
},
},
}
: {}),
...(input.roles.length > 0
? {
role: {

@ -2,6 +2,8 @@ import { z } from 'zod';
import { QuestionsQuestionType, Vote } from '@prisma/client';
import { TRPCError } from '@trpc/server';
import { JobTitleLabels } from '~/components/shared/JobTitles';
import { createProtectedRouter } from '../context';
export const questionsQuestionUserRouter = createProtectedRouter()
@ -9,9 +11,11 @@ export const questionsQuestionUserRouter = createProtectedRouter()
input: z.object({
companyId: z.string(),
content: z.string(),
location: z.string(),
cityId: z.string().nullish(),
countryId: z.string(),
stateId: z.string().nullish(),
questionType: z.nativeEnum(QuestionsQuestionType),
role: z.string(),
role: z.nativeEnum(JobTitleLabels),
seenAt: z.date(),
}),
async resolve({ ctx, input }) {
@ -27,8 +31,21 @@ export const questionsQuestionUserRouter = createProtectedRouter()
id: input.companyId,
},
},
// To do: Fix this
location: input.location,
city: input.cityId !== null ? {
connect: {
id: input.cityId,
},
} : undefined,
country: {
connect: {
id: input.countryId,
},
},
state: input.stateId !== null ? {
connect: {
id: input.stateId,
},
} : undefined,
role: input.role,
seenAt: input.seenAt,
user: {

Loading…
Cancel
Save