6ed0349507
Add full-text card search (PostgreSQL tsvector + GIN index) with navbar SearchBar, client-side board filters (label/assignee/due date), board templates (3 system templates + save-as-template API), and archive toggle for both board listing and board view. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type { PageServerLoad } from './$types.js';
|
|
import { withTenant } from '$lib/server/rls.js';
|
|
import { prisma } from '$lib/server/db.js';
|
|
|
|
export const load: PageServerLoad = async ({ locals, url }) => {
|
|
const tenant = locals.tenant;
|
|
if (!tenant) return { boards: [], categories: [], templates: [] };
|
|
|
|
const showArchived = url.searchParams.get('archived') === 'true';
|
|
|
|
const result = await withTenant(tenant.id, async (tx) => {
|
|
const where: any = { tenantId: tenant.id };
|
|
if (!showArchived) {
|
|
where.archived = false;
|
|
}
|
|
|
|
if (!locals.user) {
|
|
where.visibility = 'PUBLIC';
|
|
} else {
|
|
where.OR = [
|
|
{ visibility: 'PUBLIC' },
|
|
{ members: { some: { userId: locals.user.id } } }
|
|
];
|
|
}
|
|
|
|
const [boards, categories] = await Promise.all([
|
|
tx.board.findMany({
|
|
where,
|
|
include: {
|
|
members: {
|
|
include: { user: { select: { id: true, name: true, avatarUrl: true } } }
|
|
},
|
|
category: true,
|
|
_count: { select: { columns: true } }
|
|
},
|
|
orderBy: { updatedAt: 'desc' }
|
|
}),
|
|
locals.user
|
|
? tx.category.findMany({
|
|
where: { tenantId: tenant.id },
|
|
orderBy: { name: 'asc' }
|
|
})
|
|
: []
|
|
]);
|
|
|
|
return { boards, categories };
|
|
});
|
|
|
|
// Fetch templates (system + tenant) — only if logged in
|
|
let templates: any[] = [];
|
|
if (locals.user) {
|
|
const [systemTemplates, tenantTemplates] = await Promise.all([
|
|
prisma.boardTemplate.findMany({
|
|
where: { tenantId: null },
|
|
orderBy: { name: 'asc' }
|
|
}),
|
|
withTenant(tenant.id, async (tx) => {
|
|
return tx.boardTemplate.findMany({
|
|
where: { tenantId: tenant.id },
|
|
orderBy: { name: 'asc' }
|
|
});
|
|
})
|
|
]);
|
|
templates = [...systemTemplates, ...tenantTemplates];
|
|
}
|
|
|
|
return { ...result, templates };
|
|
};
|