eee0885811
- Remove recursive directory size calculations (single Seafile API call per list) - Remove 'Used in this location' usage display - Fix move using v2 per-type endpoints instead of broken batch endpoint - Send entry type from frontend for correct move routing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
|
|
|
const corsHeaders = {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
};
|
|
|
|
serve(async (req) => {
|
|
if (req.method === 'OPTIONS') return new Response('ok', { headers: corsHeaders });
|
|
|
|
try {
|
|
const { invoice_id, invoice_ref } = await req.json();
|
|
const invoiceRef = invoice_ref || invoice_id;
|
|
|
|
if (!invoiceRef) {
|
|
return new Response(JSON.stringify({ error: 'invoice_ref required' }), {
|
|
status: 400,
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
|
|
const supabase = createClient(
|
|
Deno.env.get('SUPABASE_URL')!,
|
|
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!,
|
|
);
|
|
|
|
let invoice = null;
|
|
let error = null;
|
|
|
|
({ data: invoice, error } = await supabase
|
|
.from('invoices')
|
|
.select('id, invoice_number, invoice_date, due_date, total, status, bill_to, company_id')
|
|
.eq('id', invoiceRef)
|
|
.maybeSingle());
|
|
|
|
if (!invoice) {
|
|
({ data: invoice, error } = await supabase
|
|
.from('invoices')
|
|
.select('id, invoice_number, invoice_date, due_date, total, status, bill_to, company_id')
|
|
.eq('invoice_number', invoiceRef)
|
|
.maybeSingle());
|
|
}
|
|
|
|
if (error || !invoice) {
|
|
return new Response(JSON.stringify({ error: 'Invoice not found' }), {
|
|
status: 404,
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
|
|
const { data: company } = invoice.company_id
|
|
? await supabase
|
|
.from('companies')
|
|
.select('name, email')
|
|
.eq('id', invoice.company_id)
|
|
.maybeSingle()
|
|
: { data: null };
|
|
|
|
return new Response(JSON.stringify({ invoice: { ...invoice, companies: company || null } }), {
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
|
});
|
|
} catch (err) {
|
|
console.error(err);
|
|
return new Response(JSON.stringify({ error: err.message }), {
|
|
status: 500,
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
});
|