feat: enhance API response handling and add new components for module management
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 4m50s
Workflow / ⚫️ Test (push) Has been skipped

This commit is contained in:
T. Zehetbauer
2026-04-01 15:18:24 +02:00
parent f82a366a52
commit 7b078f298b
58 changed files with 1845 additions and 398 deletions

View File

@@ -64,7 +64,14 @@ export const generateSepaXml = authActionClient
creditorId: input.creditorId,
});
logger.info({ name: 'finance.generateSepaXml' }, 'SEPA XML generated');
return { success: true, xml: result };
return {
success: true,
data: {
content: result,
filename: `sepa-einzug-${new Date().toISOString().split('T')[0]}.xml`,
mimeType: 'application/xml',
},
};
});
export const createInvoice = authActionClient
@@ -99,5 +106,5 @@ export const populateBatchFromMembers = authActionClient
{ name: 'sepa.populate', count: result.addedCount },
'Populated',
);
return { success: true, addedCount: result.addedCount };
return { success: true, data: { addedCount: result.addedCount } };
});

View File

@@ -20,14 +20,43 @@ export function createFinanceApi(client: SupabaseClient<Database>) {
return {
// --- SEPA Batches ---
async listBatches(accountId: string) {
const { data, error } = await client
async listBatches(
accountId: string,
opts?: {
search?: string;
status?: string;
page?: number;
pageSize?: number;
},
) {
const page = opts?.page ?? 1;
const pageSize = opts?.pageSize ?? 25;
let query = client
.from('sepa_batches')
.select('*')
.select('*', { count: 'exact' })
.eq('account_id', accountId)
.order('created_at', { ascending: false });
if (opts?.search) {
query = query.ilike('description', `%${opts.search}%`);
}
if (opts?.status) {
query = query.eq('status', opts.status);
}
query = query.range((page - 1) * pageSize, page * pageSize - 1);
const { data, error, count } = await query;
if (error) throw error;
return data ?? [];
return {
data: data ?? [],
total: count ?? 0,
page,
pageSize,
totalPages: Math.ceil((count ?? 0) / pageSize),
};
},
async getBatch(batchId: string) {
@@ -148,20 +177,48 @@ export function createFinanceApi(client: SupabaseClient<Database>) {
},
// --- Invoices ---
async listInvoices(accountId: string, opts?: { status?: string }) {
async listInvoices(
accountId: string,
opts?: {
search?: string;
status?: string;
page?: number;
pageSize?: number;
},
) {
const page = opts?.page ?? 1;
const pageSize = opts?.pageSize ?? 25;
let query = client
.from('invoices')
.select('*')
.select('*', { count: 'exact' })
.eq('account_id', accountId)
.order('issue_date', { ascending: false });
if (opts?.status)
if (opts?.status) {
query = query.eq(
'status',
opts.status as Database['public']['Enums']['invoice_status'],
);
const { data, error } = await query;
}
if (opts?.search) {
query = query.or(
`invoice_number.ilike.%${opts.search}%,recipient_name.ilike.%${opts.search}%`,
);
}
query = query.range((page - 1) * pageSize, page * pageSize - 1);
const { data, error, count } = await query;
if (error) throw error;
return data ?? [];
return {
data: data ?? [],
total: count ?? 0,
page,
pageSize,
totalPages: Math.ceil((count ?? 0) / pageSize),
};
},
async createInvoice(input: CreateInvoiceInput, userId: string) {