|
|
@ -9,12 +9,14 @@ import type { Question } from '~/types/questions-question';
|
|
|
|
export const questionsQuestionsRouter = createProtectedRouter()
|
|
|
|
export const questionsQuestionsRouter = createProtectedRouter()
|
|
|
|
.query('getQuestionsByFilter', {
|
|
|
|
.query('getQuestionsByFilter', {
|
|
|
|
input: z.object({
|
|
|
|
input: z.object({
|
|
|
|
content: z.string(),
|
|
|
|
company: z.string().optional(),
|
|
|
|
|
|
|
|
location: z.string().optional(),
|
|
|
|
questionType: z.nativeEnum(QuestionsQuestionType),
|
|
|
|
questionType: z.nativeEnum(QuestionsQuestionType),
|
|
|
|
|
|
|
|
role: z.string().optional(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
async resolve({ ctx, input }) {
|
|
|
|
async resolve({ ctx, input }) {
|
|
|
|
const questionsData = await ctx.prisma.questionsQuestion.findMany({
|
|
|
|
const questionsData = await ctx.prisma.questionsQuestion.findMany({
|
|
|
|
include: {
|
|
|
|
include: {
|
|
|
|
_count: {
|
|
|
|
_count: {
|
|
|
|
select: {
|
|
|
|
select: {
|
|
|
|
answers: true,
|
|
|
|
answers: true,
|
|
|
@ -28,9 +30,12 @@ export const questionsQuestionsRouter = createProtectedRouter()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
votes: true,
|
|
|
|
votes: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
orderBy: {
|
|
|
|
orderBy: {
|
|
|
|
createdAt: 'desc',
|
|
|
|
createdAt: 'desc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return questionsData.map((data) => {
|
|
|
|
return questionsData.map((data) => {
|
|
|
|
const votes:number = data.votes.reduce(
|
|
|
|
const votes:number = data.votes.reduce(
|
|
|
@ -104,7 +109,8 @@ export const questionsQuestionsRouter = createProtectedRouter()
|
|
|
|
const questionToUpdate = await ctx.prisma.questionsQuestion.findUnique({
|
|
|
|
const questionToUpdate = await ctx.prisma.questionsQuestion.findUnique({
|
|
|
|
where: {
|
|
|
|
where: {
|
|
|
|
id: input.id,
|
|
|
|
id: input.id,
|
|
|
|
},});
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (questionToUpdate?.id !== userId) {
|
|
|
|
if (questionToUpdate?.id !== userId) {
|
|
|
|
throw new TRPCError({
|
|
|
|
throw new TRPCError({
|
|
|
|