mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-30 05:34:33 +08:00
[questions][feat] add encounters sorting (#458)
Co-authored-by: Bryann Yeap Kok Keong <bryannyeapkk@gmail.com> Co-authored-by: Ai Ling <hong-ailing@hotmail.com> Co-authored-by: Zhang Ziqing <zhangziqing9926@gmail.com> Co-authored-by: Bryann Yeap Kok Keong <77266823+BryannYeap@users.noreply.github.com>
This commit is contained in:
@ -27,24 +27,40 @@ export const questionsQuestionRouter = createRouter()
|
||||
async resolve({ ctx, input }) {
|
||||
const { cursor } = input;
|
||||
|
||||
const sortCondition =
|
||||
input.sortType === SortType.TOP
|
||||
? [
|
||||
{
|
||||
upvotes: input.sortOrder,
|
||||
},
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
lastSeenAt: input.sortOrder,
|
||||
},
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
];
|
||||
let sortCondition = undefined;
|
||||
|
||||
switch (input.sortType) {
|
||||
case SortType.TOP:
|
||||
sortCondition = [
|
||||
{
|
||||
upvotes: input.sortOrder,
|
||||
},
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
]
|
||||
break;
|
||||
case SortType.NEW:
|
||||
sortCondition = [
|
||||
{
|
||||
lastSeenAt: input.sortOrder,
|
||||
},
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
];
|
||||
break;
|
||||
case SortType.ENCOUNTERS:
|
||||
sortCondition = [
|
||||
{
|
||||
numEncounters: input.sortOrder,
|
||||
},
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
const questionsData = await ctx.prisma.questionsQuestion.findMany({
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
|
Reference in New Issue
Block a user