Fix TypeScript errors in API endpoints

This commit is contained in:
GitHub Copilot
2025-05-06 11:38:37 +00:00
parent bfa57a9655
commit 984cd42f27
3 changed files with 14 additions and 15 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -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