|
|
|
@ -9,7 +9,7 @@ import type { Question } from '~/types/questions';
|
|
|
|
|
export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
.query('getQuestionsByFilter', {
|
|
|
|
|
input: z.object({
|
|
|
|
|
companies: z.string().array(),
|
|
|
|
|
companyNames: z.string().array(),
|
|
|
|
|
endDate: z.date(),
|
|
|
|
|
locations: z.string().array(),
|
|
|
|
|
questionTypes: z.nativeEnum(QuestionsQuestionType).array(),
|
|
|
|
@ -51,35 +51,36 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
encounters : {
|
|
|
|
|
encounters: {
|
|
|
|
|
some: {
|
|
|
|
|
...(input.companies.length > 0
|
|
|
|
|
...(input.companyNames.length > 0
|
|
|
|
|
? {
|
|
|
|
|
company : {
|
|
|
|
|
in : input.companies
|
|
|
|
|
}
|
|
|
|
|
company: {
|
|
|
|
|
name: {
|
|
|
|
|
in: input.companyNames,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
...(input.locations.length > 0
|
|
|
|
|
? {
|
|
|
|
|
location: {
|
|
|
|
|
in: input.locations
|
|
|
|
|
in: input.locations,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
...(input.roles.length > 0
|
|
|
|
|
? {
|
|
|
|
|
role : {
|
|
|
|
|
in: input.roles
|
|
|
|
|
}
|
|
|
|
|
role: {
|
|
|
|
|
in: input.roles,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return questionsData
|
|
|
|
|
.map((data) => {
|
|
|
|
|
return questionsData.map((data) => {
|
|
|
|
|
const votes: number = data.votes.reduce(
|
|
|
|
|
(previousValue: number, currentValue) => {
|
|
|
|
|
let result: number = previousValue;
|
|
|
|
@ -98,7 +99,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const question: Question = {
|
|
|
|
|
company: data.encounters[0].company,
|
|
|
|
|
company: data.encounters[0].company!.name ?? 'Unknown company',
|
|
|
|
|
content: data.content,
|
|
|
|
|
id: data.id,
|
|
|
|
|
location: data.encounters[0].location ?? 'Unknown location',
|
|
|
|
@ -171,7 +172,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const question: Question = {
|
|
|
|
|
company: questionData.encounters[0].company,
|
|
|
|
|
company: questionData.encounters[0].company!.name ?? 'Unknown company',
|
|
|
|
|
content: questionData.content,
|
|
|
|
|
id: questionData.id,
|
|
|
|
|
location: questionData.encounters[0].location ?? 'Unknown location',
|
|
|
|
@ -189,7 +190,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
})
|
|
|
|
|
.mutation('create', {
|
|
|
|
|
input: z.object({
|
|
|
|
|
company: z.string(),
|
|
|
|
|
companyId: z.string(),
|
|
|
|
|
content: z.string(),
|
|
|
|
|
location: z.string(),
|
|
|
|
|
questionType: z.nativeEnum(QuestionsQuestionType),
|
|
|
|
@ -199,17 +200,25 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
async resolve({ ctx, input }) {
|
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
|
|
|
|
|
|
const question = await ctx.prisma.questionsQuestion.create({
|
|
|
|
|
return await ctx.prisma.questionsQuestion.create({
|
|
|
|
|
data: {
|
|
|
|
|
content: input.content,
|
|
|
|
|
encounters: {
|
|
|
|
|
create: [
|
|
|
|
|
{
|
|
|
|
|
company: input.company,
|
|
|
|
|
company: {
|
|
|
|
|
connect: {
|
|
|
|
|
id: input.companyId,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
location: input.location,
|
|
|
|
|
role: input.role,
|
|
|
|
|
seenAt: input.seenAt,
|
|
|
|
|
userId,
|
|
|
|
|
user: {
|
|
|
|
|
connect: {
|
|
|
|
|
id: userId,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
@ -217,20 +226,6 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
userId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create question encounter
|
|
|
|
|
await ctx.prisma.questionsQuestionEncounter.create({
|
|
|
|
|
data: {
|
|
|
|
|
company: input.company,
|
|
|
|
|
location: input.location,
|
|
|
|
|
questionId: question.id,
|
|
|
|
|
role: input.role,
|
|
|
|
|
seenAt: input.seenAt,
|
|
|
|
|
userId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return question;
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.mutation('update', {
|
|
|
|
@ -259,7 +254,6 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
|
const { content, questionType } = input;
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.questionsQuestion.update({
|
|
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
content,
|
|
|
|
|
questionType,
|
|
|
|
|