|
|
@ -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({
|
|
|
|
companies: 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,68 +51,69 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (currentValue.vote) {
|
|
|
|
switch (currentValue.vote) {
|
|
|
|
case Vote.UPVOTE:
|
|
|
|
case Vote.UPVOTE:
|
|
|
|
result += 1;
|
|
|
|
result += 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Vote.DOWNVOTE:
|
|
|
|
case Vote.DOWNVOTE:
|
|
|
|
result -= 1;
|
|
|
|
result -= 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const question: Question = {
|
|
|
|
const question: Question = {
|
|
|
|
company: data.encounters[0].company,
|
|
|
|
company: data.encounters[0].company!.name ?? 'Unknown company',
|
|
|
|
content: data.content,
|
|
|
|
content: data.content,
|
|
|
|
id: data.id,
|
|
|
|
id: data.id,
|
|
|
|
location: data.encounters[0].location ?? 'Unknown location',
|
|
|
|
location: data.encounters[0].location ?? 'Unknown location',
|
|
|
|
numAnswers: data._count.answers,
|
|
|
|
numAnswers: data._count.answers,
|
|
|
|
numComments: data._count.comments,
|
|
|
|
numComments: data._count.comments,
|
|
|
|
numVotes: votes,
|
|
|
|
numVotes: votes,
|
|
|
|
role: data.encounters[0].role ?? 'Unknown role',
|
|
|
|
role: data.encounters[0].role ?? 'Unknown role',
|
|
|
|
seenAt: data.encounters[0].seenAt,
|
|
|
|
seenAt: data.encounters[0].seenAt,
|
|
|
|
type: data.questionType,
|
|
|
|
type: data.questionType,
|
|
|
|
updatedAt: data.updatedAt,
|
|
|
|
updatedAt: data.updatedAt,
|
|
|
|
user: data.user?.name ?? '',
|
|
|
|
user: data.user?.name ?? '',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return question;
|
|
|
|
return question;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.query('getQuestionById', {
|
|
|
|
.query('getQuestionById', {
|
|
|
@ -171,7 +172,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const question: Question = {
|
|
|
|
const question: Question = {
|
|
|
|
company: questionData.encounters[0].company,
|
|
|
|
company: questionData.encounters[0].company!.name ?? 'Unknown company',
|
|
|
|
content: questionData.content,
|
|
|
|
content: questionData.content,
|
|
|
|
id: questionData.id,
|
|
|
|
id: questionData.id,
|
|
|
|
location: questionData.encounters[0].location ?? 'Unknown location',
|
|
|
|
location: questionData.encounters[0].location ?? 'Unknown location',
|
|
|
@ -189,7 +190,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.mutation('create', {
|
|
|
|
.mutation('create', {
|
|
|
|
input: z.object({
|
|
|
|
input: z.object({
|
|
|
|
company: z.string(),
|
|
|
|
companyId: z.string(),
|
|
|
|
content: z.string(),
|
|
|
|
content: z.string(),
|
|
|
|
location: z.string(),
|
|
|
|
location: z.string(),
|
|
|
|
questionType: z.nativeEnum(QuestionsQuestionType),
|
|
|
|
questionType: z.nativeEnum(QuestionsQuestionType),
|
|
|
@ -199,17 +200,25 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
async resolve({ ctx, input }) {
|
|
|
|
async resolve({ ctx, input }) {
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
|
|
|
|
|
|
|
|
const question = await ctx.prisma.questionsQuestion.create({
|
|
|
|
return await ctx.prisma.questionsQuestion.create({
|
|
|
|
data: {
|
|
|
|
data: {
|
|
|
|
content: input.content,
|
|
|
|
content: input.content,
|
|
|
|
encounters: {
|
|
|
|
encounters: {
|
|
|
|
create: [
|
|
|
|
create: [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
company: input.company,
|
|
|
|
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,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -217,20 +226,6 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|
|
|
userId,
|
|
|
|
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', {
|
|
|
|
.mutation('update', {
|
|
|
@ -259,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,
|
|
|
|