fix: update RPC calls to use company_id instead of user_id for invoice and arrival number generation (#154)
This commit is contained in:
@@ -76,6 +76,7 @@ export interface CategorizationSuggestion {
|
||||
export interface TrackingContext {
|
||||
supabase: SupabaseClient
|
||||
userId: string
|
||||
companyId?: string
|
||||
}
|
||||
|
||||
export interface CategorizationProvider {
|
||||
@@ -336,7 +337,7 @@ ${transactionList}`
|
||||
inputTokens: message.usage.input_tokens,
|
||||
outputTokens: message.usage.output_tokens,
|
||||
model: this.model,
|
||||
})
|
||||
}, tracking.companyId)
|
||||
}
|
||||
|
||||
// Extract tool_use block from response
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface ChatResult {
|
||||
export async function generateChatResponse(
|
||||
userMessage: string,
|
||||
conversationHistory: ChatMessage[],
|
||||
tracking?: { supabase: SupabaseClient; userId: string }
|
||||
tracking?: { supabase: SupabaseClient; userId: string; companyId?: string }
|
||||
): Promise<ChatResult> {
|
||||
// 1. Retrieve relevant documents
|
||||
const relevantDocs = await retrieveRelevantDocuments(userMessage)
|
||||
@@ -81,7 +81,7 @@ export async function generateChatResponse(
|
||||
inputTokens: response.usage_metadata.input_tokens ?? 0,
|
||||
outputTokens: response.usage_metadata.output_tokens ?? 0,
|
||||
model: CHATBOT_CONFIG.model,
|
||||
})
|
||||
}, tracking.companyId)
|
||||
}
|
||||
|
||||
// 7. Extract content and sources
|
||||
|
||||
@@ -403,7 +403,7 @@ export async function executeMigration(options: MigrationOptions): Promise<Migra
|
||||
|
||||
// Get next arrival number (ankomstnummer) — required NOT NULL column
|
||||
const { data: arrivalNum, error: arrivalError } = await supabase
|
||||
.rpc('get_next_arrival_number', { p_user_id: userId })
|
||||
.rpc('get_next_arrival_number', { p_company_id: userId })
|
||||
|
||||
if (arrivalError || arrivalNum == null) {
|
||||
console.error(`[migration] Supplier invoice ${inv.invoiceNumber} skipped — could not get arrival number:`, arrivalError?.message)
|
||||
|
||||
@@ -166,6 +166,7 @@ async function uploadAndCreateInboxItem(
|
||||
.from('invoice_inbox_items')
|
||||
.insert({
|
||||
user_id: userId,
|
||||
company_id: companyId,
|
||||
status: 'processing',
|
||||
source: 'upload',
|
||||
document_id: document.id,
|
||||
@@ -818,7 +819,7 @@ async function handleConfirmInboxItem(
|
||||
|
||||
// Get next arrival number
|
||||
const { data: arrivalNum, error: arrivalError } = await supabase
|
||||
.rpc('get_next_arrival_number', { p_user_id: userId })
|
||||
.rpc('get_next_arrival_number', { p_company_id: companyId })
|
||||
|
||||
if (arrivalError) {
|
||||
console.error('[invoice-inbox] Confirm: arrival number error:', arrivalError)
|
||||
|
||||
Reference in New Issue
Block a user