rahvatarkus order by creation date, latest first

This commit is contained in:
Mihkel Martin Kasterpalu 2025-02-11 15:52:49 +02:00
parent 46287d6984
commit 6847b6605c

View file

@ -1,8 +1,7 @@
import { json } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { questions, answers } from '$lib/server/db/schema';
import { eq, gt, sql } from 'drizzle-orm';
import type { Question } from '$lib/types';
import { desc, eq, gt, sql } from 'drizzle-orm';
export async function GET({ params }) {
const limit = Math.min(parseInt(params.limit) || 10, 10);
@ -30,6 +29,7 @@ export async function GET({ params }) {
))`
})
.from(questions)
.orderBy(desc(questions.createdAt))
.innerJoin(answers, eq(questions.id, answers.questionId))
.where(gt(questions.answerCount, 0))
.groupBy(questions.id)