|
|
@ -23,59 +23,76 @@ export const questionsQuestionsRouter = createProtectedRouter()
|
|
|
|
comments: true,
|
|
|
|
comments: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
encounters: {
|
|
|
|
|
|
|
|
select: {
|
|
|
|
|
|
|
|
company: true,
|
|
|
|
|
|
|
|
location: true,
|
|
|
|
|
|
|
|
role: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
user: {
|
|
|
|
select: {
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
votes: true,
|
|
|
|
votes: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
orderBy: {
|
|
|
|
orderBy: {
|
|
|
|
createdAt: 'desc',
|
|
|
|
createdAt: 'desc',
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return questionsData.map((data) => {
|
|
|
|
|
|
|
|
const votes:number = data.votes.reduce(
|
|
|
|
|
|
|
|
(previousValue:number, currentValue) => {
|
|
|
|
|
|
|
|
let result:number = previousValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(currentValue.vote) {
|
|
|
|
|
|
|
|
case Vote.UPVOTE:
|
|
|
|
|
|
|
|
result += 1
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Vote.DOWNVOTE:
|
|
|
|
|
|
|
|
result -= 1
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
0
|
|
|
|
where: {
|
|
|
|
);
|
|
|
|
questionType: input.questionType,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return questionsData
|
|
|
|
|
|
|
|
.filter((data) => {
|
|
|
|
|
|
|
|
for (let i = 0; i < data.encounters.length; i++) {
|
|
|
|
|
|
|
|
const encounter = data.encounters[i]
|
|
|
|
|
|
|
|
const matchCompany = (!input.company || (encounter.company === input.company));
|
|
|
|
|
|
|
|
const matchLocation = (!input.location || (encounter.location === input.location));
|
|
|
|
|
|
|
|
const matchRole = (!input.company || (encounter.role === input.role));
|
|
|
|
|
|
|
|
if (matchCompany && matchLocation && matchRole) {return true};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.map((data) => {
|
|
|
|
|
|
|
|
const votes:number = data.votes.reduce(
|
|
|
|
|
|
|
|
(previousValue:number, currentValue) => {
|
|
|
|
|
|
|
|
let result:number = previousValue;
|
|
|
|
|
|
|
|
|
|
|
|
let userName = "";
|
|
|
|
switch(currentValue.vote) {
|
|
|
|
|
|
|
|
case Vote.UPVOTE:
|
|
|
|
|
|
|
|
result += 1
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Vote.DOWNVOTE:
|
|
|
|
|
|
|
|
result -= 1
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (data.user) {
|
|
|
|
let userName = "";
|
|
|
|
userName = data.user.name!;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.user) {
|
|
|
|
|
|
|
|
userName = data.user.name!;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const question: Question = {
|
|
|
|
const question: Question = {
|
|
|
|
company: "",
|
|
|
|
company: "",
|
|
|
|
content: data.content,
|
|
|
|
content: data.content,
|
|
|
|
id: data.id,
|
|
|
|
id: data.id,
|
|
|
|
location: "",
|
|
|
|
location: "",
|
|
|
|
numAnswers: data._count.answers,
|
|
|
|
numAnswers: data._count.answers,
|
|
|
|
numComments: data._count.comments,
|
|
|
|
numComments: data._count.comments,
|
|
|
|
numVotes: votes,
|
|
|
|
numVotes: votes,
|
|
|
|
role: "",
|
|
|
|
role: "",
|
|
|
|
updatedAt: data.updatedAt,
|
|
|
|
updatedAt: data.updatedAt,
|
|
|
|
user: userName,
|
|
|
|
user: userName,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return question;
|
|
|
|
return question;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.mutation('create', {
|
|
|
|
.mutation('create', {
|
|
|
|