From 4589fea5cebdb2ea6721e65c47f1265c58ae8165 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Feb 2026 14:55:17 +0200 Subject: [PATCH] feat: use batch save for invoice items --- src/stores/invoices.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/stores/invoices.ts b/src/stores/invoices.ts index 5d59eba..a47dc32 100644 --- a/src/stores/invoices.ts +++ b/src/stores/invoices.ts @@ -112,15 +112,20 @@ export const useInvoicesStore = defineStore('invoices', () => { } } - async function saveInvoiceItems(invoiceId: number, items: { description: string; quantity: number; unit_price: number }[]): Promise { - for (const item of items) { - await createInvoiceItem({ - invoice_id: invoiceId, - description: item.description, - quantity: item.quantity, - rate: item.unit_price, - amount: item.quantity * item.unit_price, + async function saveInvoiceItems(invoiceId: number, items: { description: string; quantity: number; unit_price: number; time_entry_id?: number }[]): Promise { + try { + await invoke('save_invoice_items_batch', { + invoiceId, + items: items.map(item => ({ + description: item.description, + quantity: item.quantity, + unit_price: item.unit_price, + time_entry_id: item.time_entry_id || null, + })), }) + } catch (error) { + handleInvokeError(error, 'Failed to save invoice items') + throw error } }