mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 14:40:13 -08:00
Fix TypeScript errors in API endpoints
This commit is contained in:
@@ -40,12 +40,13 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
);
|
||||
}
|
||||
|
||||
// Set default values if not provided
|
||||
// Set default values and ensure proper type casting
|
||||
const data = {
|
||||
...accountData,
|
||||
balance: accountData.balance || 0,
|
||||
type: accountData.type || AccountType.CHECKING,
|
||||
status: accountData.status || AccountStatus.ACTIVE,
|
||||
balance: accountData.balance ? Number(accountData.balance) : 0,
|
||||
type: (accountData.type as AccountType) || AccountType.CHECKING,
|
||||
status: (accountData.status as AccountStatus) || AccountStatus.ACTIVE,
|
||||
notes: accountData.notes || undefined,
|
||||
};
|
||||
|
||||
// Create the account
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { transactionService } from '@data/db.service';
|
||||
import type { Transaction } from '@types';
|
||||
import type { TransactionStatus, TransactionType } from '@types';
|
||||
import type { Transaction, TransactionStatus, TransactionType } from '@types';
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
export const GET: APIRoute = async ({ params }) => {
|
||||
@@ -73,9 +72,9 @@ export const PUT: APIRoute = async ({ request, params }) => {
|
||||
if (updates.accountId !== undefined) updatedData.accountId = updates.accountId;
|
||||
if (updates.description !== undefined) updatedData.description = updates.description;
|
||||
if (updates.amount !== undefined) updatedData.amount = Number(updates.amount);
|
||||
if (updates.category !== undefined) updatedData.category = updates.category;
|
||||
if (updates.notes !== undefined) updatedData.notes = updates.notes;
|
||||
if (updates.tags !== undefined) updatedData.tags = updates.tags;
|
||||
if (updates.category !== undefined) updatedData.category = updates.category || undefined;
|
||||
if (updates.notes !== undefined) updatedData.notes = updates.notes || undefined;
|
||||
if (updates.tags !== undefined) updatedData.tags = updates.tags || undefined;
|
||||
|
||||
// Convert date to Date object if it's a string
|
||||
if (updates.date !== undefined) {
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
* - Set up proper CORS configuration
|
||||
*/
|
||||
|
||||
import { accountService, transactionService } from '@data/db.service';
|
||||
import type { Transaction } from '@types';
|
||||
import type { TransactionStatus, TransactionType } from '@types';
|
||||
import type { APIRoute } from 'astro';
|
||||
import { accountService, transactionService } from '@data/db.service';
|
||||
import type { Transaction, TransactionStatus, TransactionType } from '@types';
|
||||
|
||||
/**
|
||||
* TODO: API Improvements
|
||||
@@ -63,11 +62,11 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
date: transactionDate,
|
||||
description: transaction.description,
|
||||
amount: Number(transaction.amount),
|
||||
category: transaction.category,
|
||||
category: transaction.category || undefined,
|
||||
status: transaction.status as TransactionStatus,
|
||||
type: transaction.type as TransactionType,
|
||||
notes: transaction.notes,
|
||||
tags: transaction.tags,
|
||||
notes: transaction.notes || undefined,
|
||||
tags: transaction.tags || undefined,
|
||||
});
|
||||
|
||||
// Convert Decimal to number for response
|
||||
|
||||
Reference in New Issue
Block a user