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,10 +1,8 @@
import { db } from '$lib/db';
import { topics } from '$lib/db/schema';
import { eq } from 'drizzle-orm';
import type { PageServerLoad } from './$types';
export const load = async ({ params }) => {
return {
topics: await db.query.topics.findMany({
export const load: PageServerLoad = async () => {
const topics = await db.query.topics.findMany({
with: {
topicsToTasks: {
with: {
@@ -12,6 +10,11 @@ export const load = async ({ params }) => {
}
}
}
})
});
topics.sort((a, b) => b.topicsToTasks.length - a.topicsToTasks.length);
return {
topics
};
};