fix(invoices): add scopedForModule import after Spaces bulk-migration

Bulk-migration script swapped db.table() → scopedForModule() in queries.ts
but the import line wasn't added, leaving the file broken. Restores type-
check by importing from \$lib/data/scope (same path calendar/contacts/todo
use).

Invoice reads now flow through the Spaces scope wrapper like other
migrated modules — queries only return rows from the active space.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-20 19:16:24 +02:00
parent 394aa79328
commit 8e840046e6

View file

@ -4,7 +4,7 @@
import { useLiveQueryWithDefault } from '@mana/local-store/svelte';
import { decryptRecords } from '$lib/data/crypto';
import { db } from '$lib/data/database';
import { scopedForModule } from '$lib/data/scope';
import type {
LocalInvoice,
LocalInvoiceClient,
@ -78,7 +78,7 @@ export function toInvoiceClient(local: LocalInvoiceClient): InvoiceClient {
*/
export function useAllInvoices() {
return useLiveQueryWithDefault(async () => {
const locals = await db.table<LocalInvoice>('invoices').toArray();
const locals = await scopedForModule<LocalInvoice, string>('invoices', 'invoices').toArray();
const visible = locals.filter((i) => !i.deletedAt);
const decrypted = await decryptRecords('invoices', visible);
const today = new Date().toISOString().slice(0, 10);
@ -96,7 +96,10 @@ export function useAllInvoices() {
export function useInvoiceClients() {
return useLiveQueryWithDefault(async () => {
const locals = await db.table<LocalInvoiceClient>('invoiceClients').toArray();
const locals = await scopedForModule<LocalInvoiceClient, string>(
'invoices',
'invoiceClients'
).toArray();
const visible = locals.filter((c) => !c.deletedAt);
const decrypted = await decryptRecords('invoiceClients', visible);
return decrypted.map(toInvoiceClient).sort((a, b) => a.name.localeCompare(b.name));