sort topics based on amount of tasks

This commit is contained in:
2025-12-15 22:26:54 +01:00
parent 1d53921a73
commit e8c8779536

View File

@@ -1,17 +1,20 @@
import { db } from '$lib/db'; import { db } from '$lib/db';
import { topics } from '$lib/db/schema'; import type { PageServerLoad } from './$types';
import { eq } from 'drizzle-orm';
export const load = async ({ params }) => { export const load: PageServerLoad = async () => {
return { const topics = await db.query.topics.findMany({
topics: await db.query.topics.findMany({ with: {
with: { topicsToTasks: {
topicsToTasks: { with: {
with: { task: true
task: true
}
} }
} }
}) }
});
topics.sort((a, b) => b.topicsToTasks.length - a.topicsToTasks.length);
return {
topics
}; };
}; };