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

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

Loading…
Cancel
Save